Thursday, January 30, 2014

using some of the SPUtility Methods

HandleAccessDenied using

SPUtility.HandleAccessDenied(new AccessDeniedException("ACCESS DENIED"));
(or)
SPUtility.HandleAccessDenied(new Exception("You do not have access to this page."));


SendEmail using

SPUtility.SendEmail(webObj, false, false, "e-mail_address", "Web Discussion Report", Msg);
(or)
StringDictionary headers = new StringDictionary();
headers.add("to","reginald@myfatblog.co.uk");
headers.add("cc","thisiscopy@myfatblog.co.uk");
headers.add("bcc","thisistheblindcopy@myfatblog.co.uk");
headers.add("from","MySharePointEmail@myfatblog.co.uk");
headers.add("subject","How to use SendEMail from SPUtility");
headers.add("content-type","text/html"); //This is the default type, so isn't neccessary.
string bodyText ="This is the body of my email, in html format.";
SPUtility.SendEmail(web, headers, bodyText);
using GetFullUrl
Some SharePoint objects expose relative paths.
Relative paths can be converted to full Url by adding current server, site paths.
To convert a relative path to the full URL, you add the current server,
Rather than performing path manipulation, "GetFullUrl" method can be used.
Example- Get Full Url Of A SharePoint List
SPUtility.GetFullUrl(SPContext.Current.Site, listobj.DefaultDisplayFormUrl);
Example- Get Full Url Of A SharePoint ListItem
SPUtility.GetFullUrl(SPContext.Current.Site,"/"+ itemobj.Url);
Using GetListGuid
Guid id = SPUtility.GetListGuid(webObj,strListName);
Using Redirect
SPUtility.Redirect(“/MyFolder/MyPage.aspx”, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
On SharePoint 2010 it will redirect tohttp://yoursite/_layouts/MyFolder/MyPage.aspx while on SharePoint 2013 it will redirect to http://yoursite/_layouts/15/MyFolder/MyPage.aspx. You see that in SharePoint 2013 the URL it contains the HIVE folder while in 2010 it doesn’t. Using the Redirect method with the RelativeToLayoutsPage option you don’t have to worry about that.
Other Reference:

TransferToErrorPage and TransferToSuccessPage

SPUtility.TransferToErrorPage("Hi this is an Error Page {0}, {1}", "click here to Go to Top site", "{your_url}");
SPUtility.TransferToSuccessPage("Hi this is an Sucess Page");
Reference:

No comments:

Post a Comment

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...