Insert Values Into The URL With C#

This method will help you when you need to insert parameters into the URL string.

[csharp]

public static string InsertURLParameters(string url, int listItemID, Page returnToPage)
{
        string firstInjection = SharePointTools.InsertURLParameters(url, listItemID, false);
        string formatInjection = string.Format(“Source={0}”, SPEncode.UrlEncode(returnToPage.Request.Url.AbsoluteUri));
        return InsertURLParameters(firstInjection, formatInjection, false);
}

public static string InsertURLParameters(string url, string parameters, bool insertInFront)
{
        if (url.IndexOf(‘?’) >= 0)
        {
                if (insertInFront)
                {
                        url = url.Replace(“?”, string.Format(“?{0}&”, parameters));
                        return url;
                }
                url = url + string.Format(“&{0}”, parameters);
                return url;
        }
        url = url + string.Format(“?{0}”, parameters);
        return url;
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *