September 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Build a SharePoint Newsletter Generator That Alerts Users to Changes

  • October 28, 2005
  • By Jeffrey Juday
  • Send Email »
  • More Articles »

Windows SharePoint Services (WSS) is the Microsoft document collaboration standard. As many organizations do, Microsoft leverages SharePoint as the platform for its portal site as well. Lured by SharePoint's simple site configuration and intuitive interface, many companies have placed their human resources and financial reporting information on multiple SharePoint sites for anyone in their organizations to access.

With SharePoint, building Web sites is now a possibility for any user, and users have taken advantage of this capability in a big way. This has brought about a new dilemma: how to manage all of the information on tens or hundreds of SharePoint sites. Making users aware of new or changed content is a good first step.

SharePoint does have subscription features for notifying users when changes occur. The notifications require active intervention by the user, and they send a separate email for each change. How do you make users aware without inundating them with email every time a document on the site changes? Oftentimes, a user simply requires a periodic summary of the changes.

This article demonstrates how you can leverage the SharePoint SDK classes to build a tool that collects all the changes to a site. (The tool is called a Newsletter Generator because it presents the collected changes in a Newsletter format.) It begins with a summary of the application and then discusses its implementation.

The Newsletter Application

This example uses the SharePoint SDK to implement the demonstration as an ASP.NET application. An ASP.NET solution is appropriate for the following reasons:
  • A Web Part would have taken longer to develop and given the requirements no advantage over the ASP.NET application.
  • A desktop application would've required the Web Services API or access to the server. For performance and broader capabilities, the example uses the Microsoft.SharePoint assembly. Also, the Newsletter application users are not server administrators, and giving anyone but an administrator direct access to the server is not a best practice.

Figure 1 shows a screen capture of the Newsletter application.



Click here for a larger image.

Figure 1: The Newsletter Application

The application sends newsletters at monthly intervals. To send only the changes that occurred since a point in time, the application allows the user to select the starting point. The application also has options to include new documents (Date Created), changed documents (Date Modified), or both (changed and created).

Newsletter also allows the user to start on any site on the SharePoint server. Recurse instructs the application to include subsites of the current site.

Newsletter information in HTML format is generated at the bottom of the application. Generated information can be edited and emailed.

It's time to look at some of the changes to SharePoint that the solution's implementation requires.

SharePoint Changes

In a typical newsletter, each news item contains a title followed by a blurb that summarizes the content. This newsletter demonstration ignores some documents. To implement both requirements, some additional properties must be added to the documents contained in SharePoint.

The "Add Columns" feature inside the "Modify Settings and Columns" option in the Document library allows adding or removing document properties. Figure 2 shows the properties added to the Documents that this example includes in the newsletter.



Click here for a larger image.

Figure 2: Properties Added to the Documents

A dropdown menu on the document allows you to modify properties after a document has been added to the Library (see Figure 3).

Figure 3: Dropdown Menu to Modify Properties

With SharePoint configured to support the newsletter demonstration, the remaining task is to build the Newsletter program.

The SharePoint SDK Classes

SharePoint is logically partitioned in a hierarchal fashion. At the top of the hierarchy are Virtual Servers. Virtual Servers handle things like authentication configuration and IIS Application Pool. Each Virtual Server contains groups of Web sites called Site Collections. Site Collections allow you to manage multiple SharePoint Web sites.

Keep in mind that Site Collection refers to the SharePoint Site Collection and not a collection object you normally access in the .NET Framework.

The following three classes are critical for navigating SharePoint and manipulating files in SharePoint:

  • SPSite provides access to SharePoint Site Collections and allows you to navigate between SharePoint sites.
  • SPWeb provides methods for accessing objects in a given site.
  • SPFolder allows you to manipulate documents in a document library or list.

In a moment you'll dive into some C# code, but first review how to use the class objects to access SharePoint. To access the Web site containing the Site Collection, along with all the document libraries on the site, start by opening a SPSite class using the URL for the site. SPSite includes an OpenWeb() method for accessing the site containing the collection. OpenWeb() returns a SPWeb object. SPWeb contains a folders collection for accessing document libraries.

You can access the SharePoint classes in two ways: a Web service and a .NET assembly (Microsoft.SharePoint). This example opts for the .NET assembly because of its increased speed and functionality.

Now that you're familiar with the SharePoint objects, you can move on to the implementation details.

Applying the SharePoint SDK

The GetWebDetails function utilizes the classes discussed in the previous section to generate the newsletter. The following snippet of code is from the GetWebDetails function:
            private void GetWebDetails(SPWeb web)
            {
                        // enumerate over all the folders on the web
                  foreach(SPFolder folder in web.Folders)
                  {           
                        GetFolderDetails(folder);
                  }
 
                  // Do the same for all subwebs
                  if(m_RecurseWebs)
                  {
                        foreach(SPWeb subWeb in web.Webs)
                        {                             
                              GetWebDetails(subweb);
                        }
                  }
 
            }

GetWebDetails first collects the newsletter information from the root site. Next, if the "Recurse" option has been selected, the application proceeds to visit all of the subsites and the subsites of the subsites. The subroutine GetWebDetails is invoked continuously until all subsites have been visited.

You're probably wondering why the example doesn't utilize the AllWebs collection on the SPWeb class. The recursive functionality allows you to more easily augment the program later. For example, adding a "depth" option would restrict the function to visit only a certain number of levels of subsites.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel