It is a static object that contains a number of useful functions.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.
Miembros:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility_members.aspx
Algunas funciones útiles:
To access the object, you need to add the following using statement:
using Microsoft.SharePoint.Utilities;
I had a quick go through the SDK, an the following are what strikes me as some of the more useful functions this object provides (note, I havent used all of these yet, just went through the SDK then googled the functions I thought sounded interesting):
- SPUtility.FormatDate
Allows you to format a given date to any of the SPDateFormat typesDateTime curDate = DateTime.Now();
DateTime regionDate = web.RegionalSettings.TimeZone.UTCToLocalTime(web.ParentWeb.RegionalSettings.TimeZone.LocalTimeToUTC(curDate));
return Convert.ToDateTime(SPUtility.FormatDate(web, regionDate, SPDateFormat.ISO8601)); - Get the 14-Hive filesystem path
Returns the filesystem path for the 14-Hive, or any of the folders beneath it. This is typically (though not always) going to be C:\Program Files\Common Files\Microsoft Shared\web server extensions\12//Get path to features directory
//Would typically return "C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES"
string featurePath =SPUtility.GetGenericSetupPath("template\\features"); - Get Full (absolute) URL
Converts a relative Url into an absolute Url//Get url to list item
SPListItem item = spList.Items[1];
string itemUrl = SPUtility.GetFullUrl(spSite, item.Url); - Redirect to page
Send a HTTP redirect to the client's browser//Redirect to specified page, adding querystring
string url ="http://portal/TestResults/Pages/results.aspx";string queryString = "successflag=passed";
SPUtility.Redirect(url, SPRedirectFlags.Default, Context, queryString); - Send email
Lets you send an email from the context of the given SPWeb//Send email from current SPWeb
SPWeb web = SPContext.Current.Site.OpenWeb();
string subject = "Email from the " + web.Title + " web";
string body = "The body of the email";SPUtility.SendEmail(web, false, false,"someone@somewhere.com", subject, body);
- Transfer to SharePoint success/error page
Allows you to transfer the browser to the ootb error and success pages//Transfer to Error Page
SPUtility.TransferToErrorPage(ex.Message);//Transfer to success page, and specify url to move onto after "Ok" clicked
SPUtility.TransferToSuccessPage("Operation was completed", @"/Docs/default.aspx", "", "");
Más información:
Enviar un mail con SPUtility: http://oscarmartin.org/sharepoint-2010/como-enviar-un-email-con-sharepoint-programaticamente/ ; http://sharepointserved.blogspot.com/2011/05/send-email-with-html-format-using.html
Redirect con SPUtility: http://www.turhaltemizer.com/2010/10/redirect-in-sharepoint-using.html
Path del directorio de instalación:http://dotnetfollower.com/wordpress/2011/12/sharepoint-get-installation-directory-path/
Obtener el valor de un recurso para un determinado lenguaje: http://dotnetfollower.com/wordpress/2011/05/the-usage-of-sputility-getlocalizedstring/
Problema con SPUtility.ParseDate: http://blogs.edwardwilde.com/2009/11/30/sputility-dateparse-%E2%99%A5-seconds-sputility-dateparse-removes-the-time-component-if-you-parse-a-date-that-incudes-seconds/
SPUtility.js: http://kitmenke.com/blog/2011/04/26/sputility-js-0-8-and-beyond/
No hay comentarios:
Publicar un comentario