需要添加方法:
///<summary>
///获取URL参数
///</summary>
///<param name="key"></param>
///<returns></returns>
public static string GetUrlParam(string key)
{
try
{
Dictionary<string, string> SysUrlParamList = GetQueryStringParameters();
if (SysUrlParamList != null && SysUrlParamList[key] != null)
{
return SysUrlParamList[key];
}
else
return string.Empty;
}
catch (Exception ex)
{
//System.Windows.Forms.MessageBox.Show(ex.Message);
}
return string.Empty;
}
///<summary>
///获取URL参数集合
///</summary>
///<returns></returns>
public static Dictionary<string, string> GetQueryStringParameters()
{
Dictionary<string, string> nameValueTable = new Dictionary<string, string>();
try
{
if (ApplicationDeployment.IsNetworkDeployed)
{
string url = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
string queryString = (new Uri(url)).Query;
queryString = queryString.TrimStart('?');
string[] nameValuePairs = queryString.Split('&');
foreach (string pair in nameValuePairs)
{
string[] vars = pair.Split('=');
if (!nameValueTable.ContainsKey(vars[0]))
{
nameValueTable.Add(vars[0], vars[1]);
}
}
}
}
catch(Exception ex){
}
return (nameValueTable);
}
调用方法:
String id = GetUrlParam(“id”);
/Files/yinhaosln/url.rar