tags:

views:

457

answers:

3

Hi,

We have some special requirements:

  1. From our application, launch a ClickOnce application. It will download ClickOnce app to user's cache.
  2. After it's done, the main app needs to access some file downloaded into ClickOnce app folder.

Is there any way for the main app to know the location of ClickOnce installation folder?

Thanks, yyff

A: 

Try the following

using System.Deployment.Application;
...
var dep = ApplicationDeployment.CurrentDeployment;
var path = dep.DataDirectory;

It may not be in the DataDirectory path but one of those properties is almost ceratinly what you are looking for.

JaredPar
Is this how the Click1 finds out his _own_ location?
Henk Holterman
Thanks, however, your answer is for app that's launched from ClickOnce. In my case, my main app launches ClickOnce app and is a different process. Is there any way?
yyff
A: 

Assuming the Click1 app is yours, you could save to some more accesible location. Normally you can write to User\Documents for example.

Henk Holterman
How? From what I read, developers do not control where ClickOnce app is installed to. In WinXP, it's some folder with random name under user cache. Somehow I need a way to know that folder's name, but not from app that's launched from ClickOnce.
yyff
Which is kind of difficult. The question is why the Click1 app doesn't download to for example `Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)` .
Henk Holterman
So is there a way to define download location in Click1 or not? Would be glad to know if there is.
yyff
You still haven't answered if you own the click1.
Henk Holterman
Yes, we own the Click1 app.
yyff
The let the Click1 move/copy the 'file' to some more public place.
Henk Holterman
Smart answer. Thanks!
yyff
A: 

You can do this by examining the executing assembly and retrieving the location.

System.Reflection.Assembly assm = System.Reflection.Assembly.GetExecutingAssembly();

This is the location of your ClickOnce deployment. --> assm.CodeBase

RobinDotNet