SPUtility

 
  • SPUtility.FormatDate

    Allows you to format a given date to any of the SPDateFormat types
DateTime 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 12-Hive filesystem path

    Returns the filesystem path for the 12-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\12\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", "", "");
    


     

 

http://www.cnblogs.com/ceci/archive/2009/10/09/1579725.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值