Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > Application.UserAppDataPath Application.LocalUserAppDataPath while debugging
 

Application.UserAppDataPath Application.LocalUserAppDataPath while debugging

Hello,

I'm pretty confused about how the debugger works as far as where the files are located.

I have small data files I want to be able to update without having to Publish the application all the time.

On Debug, the UserAppDataPath is in
Documents and Settings\UserName\Application Data\Company\AssemblyName\1.0.0.0

LocalUserAppDataPath is in
Documents and Settings\UserName\Local Settings\Application Data\Company\AssemblyName\1.0.0.0

... but that's not where my data file are located; they're still in bin\debug
so looking for them with these directories names just bring errors. (file not found)


When Publishing, the filesend up in

Documents and Settings\UserName\Local Settings\Apps\2.0\{insert garbage directory name here}\{more garbage}\AssemblyName..exe {+ more garbage}

as well as in

Documents and Settings\UserName\Local Settings\Apps\2.0\Data\{insert garbage directory name here}\{more garbage}\AssemblyName..tion {+ more garbage}\Data

andthen UserAppDataPath as well as LocalUserAppDataPath are in the path above.
thentheAppfinds my files...


So why is it different when debugging and when publishing?
How do I make the file end up in the proper User or LocalUserAppDataPath when debugging?
(i.e. How do I get to debug without having to publish to make sure the files are at the right place?)

This is frankly annoying but I'm guessing I am missing something here!

Thanks for help!




  • Moved byRoahn LuoMSFTTuesday, August 25, 2009 11:36 AMincorrect forum. (From:Visual Studio Debugger)
  • Edited byWiizzZZZ Monday, August 24, 2009 11:40 PM
  •  
WiizzZZZ  Monday, August 24, 2009 10:02 PM
Hi WiizzZZZ,

This link showsHow to Dynamically Detect Data Directory Between Debug, Release, and Publish:
http://blogs.msdn.com/winformsue/archive/2006/04/26/584559.aspx.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, August 26, 2009 10:55 AM
Hi WiizzZZZ,

Please make sure you know why you need to use UserAppDataPath. As the document indicates, data stored here is part of the user profile enabled for roaming. And it will be resolved to different value when you published the application using ClickOnce. That's why you can successfully access the files after you published the application using UserAppDataPath.

If your data is located in the bin/Debug or bin/release directory, you can use relative path to access those files directly. So I think relative path is enough here as you only need the files for test.


>So why is it different when debugging and when publishing?
>How do I make the file end up in the proper User or LocalUserAppDataPath when debugging?
>(i.e. How do I get to debug without having to publish to make sure the files are at the right place?)

The UserAppDataPath is resolved to different value is by design. If you want the files to be in the UserAppDataPath before you use them, you can try to add the following statements:

        private void button1_Click(object sender, EventArgs e)
        {
            //aabbcc.txt is located in the bin/debug or bin/release directory
            string fileName = Application.UserAppDataPath + "/aabbcc.txt";
            if (!File.Exists(fileName))
            {
                //Here we use relative path to access file in bin/debug.
                File.Copy("aabbcc.txt", fileName);
            }
        }

The above makes sure the file located in Debug directory copied to the UserAppDataPath before you use them.

Feel free to let me know if you have any concern or any further problems.

Best regards,
Bruce Zhou
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bruce.Zhou  Friday, August 28, 2009 7:10 AM
Hi WiizzZZZ,

This link showsHow to Dynamically Detect Data Directory Between Debug, Release, and Publish:
http://blogs.msdn.com/winformsue/archive/2006/04/26/584559.aspx.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, August 26, 2009 10:55 AM
Thanks for the link...

but there has to be an easier way to configure Visual Studio to do this!!!
This sounds like an insanely complicated way to work.

Isn't there a simple way to 'build' in Debug and have the file sent to the right place? some option or something? Maybe some post build action/macro? but even that seems crazy!

I can't believe Microsoft has not thought of that... or if there is a good reason not to, I would love to hear it!
WiizzZZZ  Wednesday, August 26, 2009 10:01 PM
Hi WiizzZZZ,

Please make sure you know why you need to use UserAppDataPath. As the document indicates, data stored here is part of the user profile enabled for roaming. And it will be resolved to different value when you published the application using ClickOnce. That's why you can successfully access the files after you published the application using UserAppDataPath.

If your data is located in the bin/Debug or bin/release directory, you can use relative path to access those files directly. So I think relative path is enough here as you only need the files for test.


>So why is it different when debugging and when publishing?
>How do I make the file end up in the proper User or LocalUserAppDataPath when debugging?
>(i.e. How do I get to debug without having to publish to make sure the files are at the right place?)

The UserAppDataPath is resolved to different value is by design. If you want the files to be in the UserAppDataPath before you use them, you can try to add the following statements:

        private void button1_Click(object sender, EventArgs e)
        {
            //aabbcc.txt is located in the bin/debug or bin/release directory
            string fileName = Application.UserAppDataPath + "/aabbcc.txt";
            if (!File.Exists(fileName))
            {
                //Here we use relative path to access file in bin/debug.
                File.Copy("aabbcc.txt", fileName);
            }
        }

The above makes sure the file located in Debug directory copied to the UserAppDataPath before you use them.

Feel free to let me know if you have any concern or any further problems.

Best regards,
Bruce Zhou
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bruce.Zhou  Friday, August 28, 2009 7:10 AM

You can use google to search for other answers

Custom Search

More Threads

• Defining custom permissions for ClickOnce
• .deploy file not found
• ClickOnce Lauch Utility Problems
• ClickOnce Certificate Signing fails in Win2003 Application Mode
• Publish Question
• Carat Symbol Removed During Install
• Could Not Register Type Library error
• Need More Control, During ClickOnce Deployment From CD.
• ClickOnce deployment fails when both SSL is enabled and "require client
• Cannot add files to any deployment project