Redirect Page in sharepoint

Last week i ran into a strange issue while redirecting from one page to other in SharePoint. The response.redirect ofcourse is not enough for sharepoint so i tried SPUtility.Redirect. This however caused a mess while sending parameters or may be i was little crazy that day. Well anyways, to make my life easier i noted down some important things about SPUtility.Redirect i mean how you use it and how to pass various parameters to the next page.

So, lets assume we url and queryString as below

string url = "http://SPSite/Pages/SourcePage.aspx";

string queryString = "author=Isha";

The redirect would be

SPUtility.Redirect(url, SPRedirectFlags.Default, Context, queryString);

The SPRedirectFlags enumeration has these possible values:
• CheckUrl
• Default
• DoNotEncodeUrl
• DoNotEndResponse
• RelativeToLayoutsPage
• RelativeToLocalizedLayoutsPage
• Static
• Trusted
• UseSource

now lets see another example of how to redirect to a custom application page(created in sharepoint 2010) which is stored in _layouts folder

Assuming we have to redirect to a page with below url -
http://mysite/site/_layouts/demo.aspx

Then the redirection will be

SPUtility.Redirect("demo.aspx", SPRedirectFlags.Static | SPRedirectFlags.RelativeToLayoutsPage,
HttpContext.Current);

That's it! Easy enough huuu

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com