1

I want to check my url to have a source and redirect to it.

I have a button for add a ListItem, i want where doesn't have a source in URL the page refresh, where have a source in URL --> redirect me to the source..

This is my URL :

http://ue-sps2/TestSite/Lists/linkBi/NewForm.aspx?RootFolder=%2FTestSite%2FLists%2FWayBill&ContentTypeId=0x0100AA8F1829F56BF44B89174066B393D0D0001DE65983974F8844815B824AF22378F0&Source=http%3A%2F%2Fsf%2Dspsdev02%2FTestSite%2FLists%2FWayBill%2FAllItems%2Easpx

code redirect me to

http://ue-sps2/TestSite/Lists/linkBi/NewForm.aspx

I want to redirect me to Source=http%3A%2F%2Fsf%2Dspsdev02%2FTestSite%2FLists%2FlinkBi%2FAllItems%2Easpx

http://ue-sps2/TestSite/Lists/linkBi/AllItems.aspx
  • Please add some of more details as it is unclear what are you trying which methodology you want to apply. – Aakash Maurya May 31 '16 at 7:32
  • I added more details. – Goshky May 31 '16 at 7:40
2

To go more precise I would like to code it in following manner.

if (Request.QueryString.Count > 0) {

    string urlSource = Request.QueryString["Source"];

    if (!String.IsNullOrEmpty(urlSource))
    {
        int pos = urlSource.LastIndexOf(@"/");
        String newUrl = urlSource.Substring(0, pos + 1) + "/AllItems.aspx";
        SPUtility.Redirect(newUrl, SPRedirectFlags.Default, HttpContext.Current);
    }
}
2

If I understood you correctly, then following is your requirement.

  1. Checking whether Source exists in query string or not
  2. If it exists, then redirect to that URL

Example

string source = Request.QueryString["Source"];

if (source != "")
{
   SPUtility.Redirect(source, SPRedirectFlags.Default, HttpContext.Current);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.