Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SPUtility Class

Provides tools for converting date and time formats, for obtaining information from user names, for modifying access to sites, and for various other tasks in managing deployments of Microsoft SharePoint Foundation.


Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

[ClientCallableTypeAttribute(Name = "Utility", ServerTypeId = "{16f43e7e-bf35-475d-b677-9dc61e549339}")]
public static class SPUtility

Because all the methods of the SPUtility class are static, you do not need to instantiate the class to use them.

The following code example iterates through the collection of document discussions for a document library and uses the SendEmail method of the SPUtility class to send email notification to a specified address if the total number of comments made about a document is more than 20.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

SPWeb site = SPControl.GetContextWeb(Context);

string Msg = "";

SPDocDiscussionCollection discs = site.GetDocDiscussions("Document_Library_Name");

foreach (SPDocDiscussion disc in discs)
   if (disc.CommentCount > 20)
      Msg = "The file <A href='" + disc.DocUrl.ToString() + "'>" + disc.DocUrl.ToString() + 
         "</A> has received " + disc.CommentCount.ToString() + " comments.";

      SPUtility.SendEmail(site, false, false, "e-mail_address", "Web Discussion Report", Msg);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft