Clickonce deployment and args

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anders Elmén

    #1

    Clickonce deployment and args

    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.Ena bleVisualStyles ();
    Application.Set CompatibleTextR enderingDefault (false);
    Application.Run (new Forms.MainForm( args));
    }

    Regards
    Anders Elmén


  • Andy

    #2
    Re: Clickonce deployment and args

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

    HTH
    andy

    Comment

    • Anders Elmén

      #3
      Re: Clickonce deployment and args

      Hello Andy,

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

      \\Myserver\MyAp p\my.applicatio n 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


      [color=blue]
      > Startup the MageUi program; there's an option on the deployment
      > manefist that allows you to specify arguments via the URL.
      >
      > HTH
      > andy[/color]


      Comment

      • Andy

        #4
        Re: Clickonce deployment and args

        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?

        Comment

        • Anders Elmén

          #5
          Re: Clickonce deployment and args

          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<stri ng, string> GetQueryStringP arameters()
          {
          Dictionary<stri ng, string> nameValueTable = new Dictionary<stri ng, string>();

          if (ApplicationDep loyment.IsNetwo rkDeployed)
          {
          string url = AppDomain.Curre ntDomain.SetupI nformation.Acti vationArguments .ActivationData[0];
          string queryString = (new Uri(url)).Query ;
          string[] nameValuePairs = queryString.Spl it('&');
          foreach (string pair in nameValuePairs)
          {
          string[] vars = pair.Split('=') ;
          if (!nameValueTabl e.ContainsKey(v ars[0]))
          {
          nameValueTable. Add(vars[0], vars[1]);
          }
          }
          }

          return (nameValueTable );
          }

          If i translate this into my own application



          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

          [color=blue]
          > 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?
          >[/color]


          Comment

          • Anders Elmén

            #6
            Re: Clickonce deployment and args

            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.Deployme nt.Application;

            static void Main(string[] args)
            {
            string lParameter = "CompanyCod e";
            Application.Ena bleVisualStyles ();
            Application.Set CompatibleTextR enderingDefault (false);
            string[] AppArgs = new string[] { "" };

            if (ApplicationDep loyment.IsNetwo rkDeployed)
            {
            Dictionary<stri ng, string> param = GetQueryStringP arameters();
            if (!param.TryGetV alue(lParameter , out AppArgs[0]))
            {
            MessageBox.Show (string.Format( "Missing parameter {0}",lParameter ));
            return;
            }
            }
            else
            {
            AppArgs = args;
            }
            Application.Run (new Forms.MainForm( AppArgs));
            }

            static Dictionary<stri ng, string> GetQueryStringP arameters()
            {
            Dictionary<stri ng, string> nameValueTable = new Dictionary<stri ng,
            string>();

            if (ApplicationDep loyment.IsNetwo rkDeployed)
            {
            string url = AppDomain.Curre ntDomain.SetupI nformation.Acti vationArguments .ActivationData[0];
            string queryString = (new Uri(url)).Query ;
            string[] nameValuePairs = queryString.Spl it('&');
            foreach (string pair in nameValuePairs)
            {
            string[] vars = pair.Split('=') ;
            if (!nameValueTabl e.ContainsKey(v ars[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 GetQueryStringP arameters()
            method only splits the & sign.
            Feel free to add a split function on the ? sign.

            Regards,
            Anders Elmén


            [color=blue]
            > 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<stri ng, string> GetQueryStringP arameters()
            > {
            > Dictionary<stri ng, string> nameValueTable = new Dictionary<stri ng,
            > string>();
            > if (ApplicationDep loyment.IsNetwo rkDeployed)
            > {
            > string url =
            > AppDomain.Curre ntDomain.SetupI nformation.Acti vationArguments .Activatio
            > nData[0];
            > string queryString = (new Uri(url)).Query ;
            > string[] nameValuePairs = queryString.Spl it('&');
            > foreach (string pair in nameValuePairs)
            > {
            > string[] vars = pair.Split('=') ;
            > if (!nameValueTabl e.ContainsKey(v ars[0]))
            > {
            > nameValueTable. Add(vars[0], vars[1]);
            > }
            > }
            > }
            > return (nameValueTable );
            > }
            > If i translate this into my own application
            >
            > http://andelm/Ericsson/BankGuar/Bank...ar.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
            >[color=green]
            >> 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?
            >>[/color][/color]


            Comment

            • Andy

              #7
              Re: Clickonce deployment and args

              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

              Comment

              Working...