Mega Code Archive

 
Categories / C# / Network
 

Build Query String

using System; using System.Collections.Generic; using System.Text; using System.Web; namespace ARF.Web.Utility {     public class XslFunctions     {         public static string BuildQueryString(string newValues, string s1)         {             return BuildQueryString(newValues, s1, "", "", "");         }         public static string BuildQueryString(string newValues, string s1, string s2)         {             return BuildQueryString(newValues, s1, s2, "", "");         }         public static string BuildQueryString(string newValues, string s1, string s2, string s3)         {             return BuildQueryString(newValues, s1, s2, s3, "");         }         public static string BuildQueryString(string newValues, string s1, string s2, string s3, string s4)         {             StringBuilder oResult = new StringBuilder("?" + newValues);             string[] remove = new string[] { s1, s2, s3, s4 };             List<string> oKeysToRemove = new List<string>(remove);             System.Collections.Specialized.NameValueCollection qs = HttpContext.Current.Request.QueryString;                          foreach (string sKey in qs.AllKeys)             {                 if (!oKeysToRemove.Contains(sKey.ToLower()) && !oKeysToRemove.Contains(sKey))                     oResult.Append(string.Format("&{0}={1}", sKey, qs[sKey]));             }             return oResult.ToString();         }     } }