views:

369

answers:

2

Hi,

I'm trying to launch my ClickOnce application using C# code with HttpWebRequest class. The application can be deployed fine using IE. But when doing the deployment with my code, it seems only the .application file is downloaded to client.

My code is as below.

        HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create("http://localhost/test/test.application");
        getRequest.Method = "GET";
        getRequest.Timeout = 500000;                   //default is 100 seconds  

        HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
        string loginUrl = getResponse.ResponseUri.AbsoluteUri;
        StreamReader responseReader = new StreamReader(getResponse.GetResponseStream());
        string responseData = responseReader.ReadToEnd();
        responseReader.Close();

Is there anything I'm doing wrong with my code?

Thanks! - Bruce

+2  A: 

I believe that there's something special that IE does when it sees a .application file. That's why ClickOnce deploys didn't work from FireFox until .NET 3.5 SP1 added a handler for it. So what you're seeing would be the correct behaviour - your app is purely pulling down the file as a stream of bytes - it doesn't know what to do with it.

If you want to programatically launch the application, I'd suggest this instead:

System.Diagnostics.Process.Start("http://localhost/test/test.application");

Update

There's a bit more information about the whole ClickOnce/FireFox thing here. Apparently a MIME-type handler is installed for IE which recognizes the application/-ms-application type and runs the file with the ClickOnce installer. It may be worth checking out some of the old FireFox add-ons that enabled this prior to .NET 3.5 SP1 and see what they did to launch the .application file programatically.

Matt Hamilton
A: 

Thanks Matt.

Bruce Li
How about an up-vote or a "mark as answer"? :)
Matt Hamilton