Listing 1: Get items within a folder

// get the current site
SPWeb site = SPControl.GetContextWeb(Context);

// set the library and view to display
string docLibName = "Shared Documents";
string viewName = "All Documents";

// get the folder
SPFolder docLibFolder = site.Folders[docLibName];

// get library and view
SPDocumentLibrary docLib = (SPDocumentLibrary)site.Lists[docLibName];
		SPView docLibView = docLib.Views["View_Name"];

// get all the items in the folder
SPListItemCollection docLibItems = docLib.GetItemsInFolder(docLibView, docLibFolder);

// loop through and display the names of the items
foreach (SPListItem item in docLibItems){
  Label1.Text += "Name: " + item["Name"] + "
"; } Listing 2: Handling Document Library Events void IListEventSink.OnEvent(SPListEvent listEvent){ // check type and handle a new document if ((listEvent.Type == SPListEventType.Insert)){ // check to see if we have an email server if (SPUtility.IsEmailServerSet(spWeb)){ // mail user to notify new document SpUtility.SendEmail(spWeb, true, true, "someone@somecompany.com", "New Document Added", listEvent.UserLoginName + " has added a new document to the" + listEvent.Title + " document library."); } } } Listing 3: Retrieving Sub Web Meta Data private string GetSubWebs(){ // get this web SPWeb oSPWeb = SPControl.GetContextWeb(Context); // retrieve all webs for the current user SPWebCollection oMyWebs = oSPWeb.GetSubwebsForCurrentUser(); // create StringBuilder to store HTML output StringBuilder sWebOut = new StringBuilder(); //get the date now for comparison in loop DateTime dtCurrent = DateTime.Now; // create Table sWebOut.AppendFormat("<TABLE>"); foreach (SPWeb oMyWeb in oMyWebs) { sWebOut.Append("<TR>"); // show title with link sWebOut.AppendFormat("<TD><a href='{0}' title='{1}'>{2}</A></TD>", SPEncode.UrlEncodeAsUrl(oMyWeb.Url),oMyWeb.Description, SPEncode.HtmlEncode(oMyWeb.Title)); // display author with mailto if configured in tool part if (bShowAuthor) sWebOut.AppendFormat("<TD><a href='mailto:{0}'>{1}</A>", oMyWeb.Author.Email, SPEncode.HtmlEncode(oMyWeb.Author.Name) + "</TD>"); // get web type (sites, workspaces, etc) if configured in tool part sWebOut.AppendFormat("<TD>{0}</TD>", GetWebType(oMyWeb)); // display date created if configured in tool part sWebOut.AppendFormat("<TD>{0}</TD>", SPEncode.HtmlEncode(SPUtility.TimeDeltaAsString(oMyWeb.Created, dtCurrent))); sWebOut.Append("</TR>"); } sWebOut.Append("</Table>"); return sWebOut.ToString(); } // protected override void RenderWebPart(HtmlTextWriter output){ output.Write(GetSubWebs()); } Listing 4: Custom Tool Part Class // Custom Tool Part public class SubSitesToolPart : ToolPart{ Label displayPrompt; CheckBox showURL; CheckBox showDescription; public SubSitesToolPart(){ this.Title="Sub Sites Properties"; } // Create controls needed for UI within Tool Part protected override void CreateChildControls(){ SubSites wp = (SubSites)ParentToolPane.SelectedWebPart; displayPrompt = new Label(); displayPrompt.Text = "Display columns"; displayPrompt.Font.Bold = true; Controls.Add(displayPrompt); // Show ToolPart URL Checkbox showURL = new CheckBox(); showURL.Text = wp.sURLTitle; showURL.Checked = wp.bShowURL; Controls.Add(showURL); // Show ToolPart Description Checkbox showDescription = new CheckBox(); showDescription.Text = wp.sDescriptionTitle; showDescription.Checked = wp.bShowDescription; Controls.Add(showDescription); } // Called by the ToolPart to apply changes to the selected web part. public override void ApplyChanges(){ SubSites wp = (SubSites)ParentToolPane.SelectedWebPart; wp.bShowURL = showURL.Checked; wp.bShowDescription = showDescription.Checked; } // Overridden method responsible for rendering all non-toolpane // parts of the ToolPart. protected override void RenderToolPart(HtmlTextWriter output){ output.Write("<div style='padding:5px;width:100%'>"); foreach (Control oControl in Controls){ oControl.RenderControl(output); output.Write("<br>"); } output.Write("</div>"); } } Listing 5: Gettoolparts Method /// called by part to display custom Tool Parts public override ToolPart[] GetToolParts(){ return new ToolPart[] { new SubSitesToolPart(), new WebPartToolPart()}; }