How to get the path to a file in the Local App Data folder created by ClickOnce

370 views Asked by At

I have a WPF project that I want to deploy via clickonce. I have a folder named "Data" with some files in it which will be created by clickonce in Local App Data folder when I install the application. I want to access those files but I am unable to figure out how to do that . The folder created by clickonce has some random name, it looks like this:

C:\Users\xxxxx\AppData\Local\Apps\2.0\Data\PG220ZY7.R26\B0O5ZOCW.BX7\oatr..tion_0000000000000000_0001.0000_73ac71b3d7a93fc2\Data\Data

How can I access those files since I have no way to know what name the clickonce will assign to that folder?

1

There are 1 answers

0
Brian On

Check if application is network deployed if not will error. Then you can get the directory with ApplicationDeployment.CurrentDeployment.DataDirectory

Example from Microsoft

        if (ApplicationDeployment.IsNetworkDeployed)
        {
            try
            {
                using (StreamReader sr = new StreamReader(ApplicationDeployment.CurrentDeployment.DataDirectory + @"\CSV.txt"))
                {
                    MessageBox.Show(sr.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not read file. Error message: " + ex.Message);
            }

        }