Home > SharePoint, sputility > SPUtility – The unnoticed gem of SharePoint

SPUtility – The unnoticed gem of SharePoint


While doing SharePoint development people tend to ignore one of the best friends, which is rather unknown. It is the SPUtility (Microsoft.SharePoint.Utility.SPUtility) class


I shall tell you some of the common scenarios where you can use the SPUtility class


1.Need to get the path of the 12 hive? what do you do? hardcode…stop doing that



SPUtility.GetGenericSetupPath(@"TEMPLATE\FEATURES")




will return you the complete local path for the specified subdirectory C:\Program Files…..


2. Transfer to an error page in SharePoint


SPUtility.TransferToErrorPage("My Error message!!">;


3. Transfer to a sucess page

SPUtility.TransferToSuccessPage("My Sucess Message");


4. Get directory from an url


SPUtility.GetUrlDirectory(string url)

If the url parameter is http://server/web/list/folder/file.txt, the returned directory part is “http://server/web/list/folder”.


5. Get filename from an url

SPUtility.GetUrlFileName(string url)


If the url parameter is http://server/web/list/folder/file.txt, the returned filename part is “file.txt”.

Advertisements
Categories: SharePoint, sputility
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: