Clickonce deployment and args

  • Thread starter =?iso-8859-1?Q?Anders=20Elm=e9n?=
  • Start date
?

=?iso-8859-1?Q?Anders=20Elm=e9n?=

Hi!

I have an application as takes 1 argument.
When i start the application from the command line it works, but after clickonce
deployment the deployed my.application does not takes arguments.
The assembly is deployed using an unc path. How do pass an argument to the
application?

The code:

static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Forms.MainForm(args));
}

Regards
Anders Elmé
 
A

Andy

Startup the MageUi program; there's an option on the deployment
manefist that allows you to specify arguments via the URL.

HTH
andy
 
?

=?iso-8859-1?Q?Anders=20Elm=e9n?=

Hello Andy,

I saw that one. But how do i start the application and pass the arguments?

\\Myserver\MyApp\my.application myarg does not work.

I know it's an UNC path, but if there is some way to do it

Do i have to share the folder using webshare?

Regards,
Anders Elmén
 
A

Andy

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?
 
?

=?iso-8859-1?Q?Anders=20Elm=e9n?=

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.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);
}

If i translate this into my own application

http://andelm/Ericsson/BankGuar/BankGuar_1_0_0_29/BankGuar.exe.manifest?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
 
?

=?iso-8859-1?Q?Anders=20Elm=e9n?=

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?
 
A

Andy

I hope that VS2003 is a typo; ClickOnce and that URL method of
parameters is only supported in .net 2.0 and VS2005.

Also, you don't want to link to the manefist, you need to link to the
..application file (aka the Deployment manifest).

HTH.
ANdy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Application.Exit(); does not end app. 4
Passing main() input arguments 3
AccessViolationException error 2
Main() questions 3
My timer doesn't work 1
forms error 3
ClickOnce 3
Noob question 2

Top