1

The problem: Clickonce puts sub-folders of a project in a different place when used in Visual Studio vs when installed as a Clickonce application.

In Visual Studio they are under:

Directory.GetParent(Environment.CurrentDirectory).Parent

While when installed, they're under:

Environment.CurrentDirectory

Though I can check for Clickonce installation (as shown in an answer to my question here , "closed as not a real question"...) I'm worried this might break at some point - unless I understand exactly why this happens.

So what’s the correct way of getting folders' paths both when running inside Visual Studio, and when installed as Clickonce?

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

0

If I correctly understood your question, try to use Application.StartupPath and ApplicationDeployment.CurrentDeployment.DataDirectory as follows:

string startupPath = ApplicationDeployment.IsNetworkDeployed
    ? ApplicationDeployment.CurrentDeployment.DataDirectory :
    : Application.StartupPath;

Or just Application.StartupPath.

Or just ApplicationDeployment.CurrentDeployment.DataDirectory.

It depends on the meaning of the "Clickonce puts sub-folders of a project"

Dmitry
  • 13,797
  • 6
  • 32
  • 48
  • Thanks, I'll have to try these. As for what I meant, here's a simple example: In my project I have a folder, `Folder1`. In it there is a file `Text1.txt` and I want my application to get its path so it can read its content. – ispiro Feb 24 '14 at 17:40
  • Definitely use `Application.StartupPath` if you included this folder in the deploying package. – Dmitry Feb 24 '14 at 17:44
  • Nope. Works when installed as Clickonce. But not when executed in VS. – ispiro Feb 24 '14 at 17:49
  • (I'm also looking into how I can tell Clickonce that they're data files. Currently I have these files as `Build Action` = `Content` simply because that's how it's done automatically.) – ispiro Feb 24 '14 at 17:50
  • Does the folder copied into the build output folder when running in VS? – Dmitry Feb 24 '14 at 17:59
  • If you mean ".../bin/debug" - No. It doesn't. – ispiro Feb 24 '14 at 18:21
  • But its files copied, aren't they? If so, they should be accessible via `Path.Combine(Application.StartupPath, "Text1.txt")` when running in VS too. – Dmitry Feb 24 '14 at 18:29