Share via


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 a deployment of Windows SharePoint Services 3.0.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Utilities.SPUtility

Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPUtility

You do not need to declare an instance of a static class in order to access its members.
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public static class SPUtility

Remarks

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

Examples

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 e-mail 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.

Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim Msg As String = ""

Dim discs As SPDocDiscussionCollection = site.GetDocDiscussions("Document_Library_Name")
Dim disc As SPDocDiscussion

For Each disc In  discs

    If disc.CommentCount > 20 Then

        Msg = "The file <A href='" & disc.DocUrl.ToString() _
            & "'>" + disc.DocUrl.ToString() & "</A> has received " _
           & disc.CommentCount.ToString() & " comments."

        SPUtility.SendEmail(site, False, False, "Email_Address", "Web Discussion Report", Msg)

    End If

Next disc
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);
   }
}

Thread Safety

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

See Also

Reference

SPUtility Members

Microsoft.SharePoint.Utilities Namespace