The solution.
1. if you want your application to receive args, publish your application
with http
2. Add this to your code in program.cs:
using System.Deployment.Application;
static void Main(string[] args)
{
string lParameter = "CompanyCode";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string[] AppArgs = new string[] { "" };
if (ApplicationDeployment.IsNetworkDeployed)
{
Dictionary<string, string> param = GetQueryStringParameters();
if (!param.TryGetValue(lParameter, out AppArgs[0]))
{
MessageBox.Show(string.Format("Missing parameter {0}",lParameter));
return;
}
}
else
{
AppArgs = args;
}
Application.Run(new Forms.MainForm(AppArgs));
}
static Dictionary<string, string> GetQueryStringParameters()
{
Dictionary<string, string> nameValueTable = new Dictionary<string,
string>();
if (ApplicationDeployment.IsNetworkDeployed)
{
string url = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
string queryString = (new Uri(url)).Query;
string[] nameValuePairs = queryString.Split('&');
foreach (string pair in nameValuePairs)
{
string[] vars = pair.Split('=');
if (!nameValueTable.ContainsKey(vars[0]))
{
nameValueTable.Add(vars[0], vars[1]);
}
}
}
return (nameValueTable);
}
}
3. Publish your application and start it with
http://server/my.application?Dummy=na&CompanyCode=01
The reason why i have to use the dummy parameter is that the GetQueryStringParameters()
method only splits the & sign.
Feel free to add a split function on the ? sign.
Regards,
Anders Elmén
Hello Andy,
Thanks for keepning this thread alive
In MDSN Documentation there is an sample of how to obtain query string
information
from a ClickOnce application.
In the sampe they use
http://servername/WindowsApp1.manifest?username=joeuser
as query string and the following method to parse the string.
private Dictionary<string, string> GetQueryStringParameters()
{
Dictionary<string, string> nameValueTable = new Dictionary<string,
string>();
if (ApplicationDeployment.IsNetworkDeployed)
{
string url =
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.Activatio
nData[0];
string queryString = (new Uri(url)).Query;
string[] nameValuePairs = queryString.Split('&');
foreach (string pair in nameValuePairs)
{
string[] vars = pair.Split('=');
if (!nameValueTable.ContainsKey(vars[0]))
{
nameValueTable.Add(vars[0], vars[1]);
}
}
}
return (nameValueTable);
}
If i translate this into my own application
http://andelm/Ericsson/BankGuar/BankGuar_1_0_0_29/BankGuar.exe.manifes
t?Company=T3
When i hit the return key a dialog box appears with the open or save
dialog. The application is not executed. When opening I get the
manifest xml file opened in VS2003.
Any idéa?
Regards,
Anders Elmén
Sorry, thought URL for UNC. Unfortunatly I don't know the answer to
that.. I'd think that what you tried would work. If you use a URL,
does it then work?