CGC_Codes

build query string

Jun 6th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web;
  5.  
  6. namespace ARF.Web.Utility
  7. {
  8.     public class XslFunctions
  9.     {
  10.         public static string BuildQueryString(string newValues, string s1)
  11.         {
  12.             return BuildQueryString(newValues, s1, "", "", "");
  13.         }
  14.  
  15.         public static string BuildQueryString(string newValues, string s1, string s2)
  16.         {
  17.             return BuildQueryString(newValues, s1, s2, "", "");
  18.         }
  19.  
  20.         public static string BuildQueryString(string newValues, string s1, string s2, string s3)
  21.         {
  22.             return BuildQueryString(newValues, s1, s2, s3, "");
  23.         }
  24.  
  25.         public static string BuildQueryString(string newValues, string s1, string s2, string s3, string s4)
  26.         {
  27.             StringBuilder oResult = new StringBuilder("?" + newValues);
  28.  
  29.             string[] remove = new string[] { s1, s2, s3, s4 };
  30.  
  31.             List<string> oKeysToRemove = new List<string>(remove);
  32.  
  33.             System.Collections.Specialized.NameValueCollection qs = HttpContext.Current.Request.QueryString;
  34.  
  35.             foreach (string sKey in qs.AllKeys)
  36.             {
  37.                 if (!oKeysToRemove.Contains(sKey.ToLower()) && !oKeysToRemove.Contains(sKey))
  38.                     oResult.Append(string.Format("&{0}={1}", sKey, qs[sKey]));
  39.             }
  40.  
  41.             return oResult.ToString();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment