I'm makeing a program that users will be able to have run on start up. In this program I need to create temporary files in their My Pictures folder. Unfortunatly sometimes this folder does not exist or user's profile has changed and the Evironment.user is no longer accurate. So what I would like to do is have the program check to see if the My Pictures folder exsists. If it does... wonderful. If it doesn't I have the user choose a directory where the temporary files can be created. My question is, is there a way that I can take the users chosen directory and be able to use it again next time the program starts up? I would like to do this without creating another file in which I would store the information (i.e. create a text file with the directory path in it). The reason is because the people that use this program don't have privlages to write anywhere. So I would like have the chosen directory be stored in the program if it is possible.
Thanks in advance.
- It's a long way to the top if you want to rock n' roll - AC/DC
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
Why not write the temporary files in the proper location rather in the My pictures folder?
See Environment.GetFolderPath( SpecialFolder.ApplicationData );
Unfortunatly the users of this program do not have sufficient privlages to save files anywhere other than their documents. The reason I need to add this capability to my program is because the users name may have changed (ie. someone got married) so their log on info chaged but not how it is accessed in their my documents. I have no idea why my company would allow this but I don't care, I get paid at the end of the week regardless. Also It allows me to learn new things about programing. Hopefully that explained my needs for this a little better.
I tried doing it and what I would like to do is have a string in the settings that points to "C:\\Documents and Settings\\Environment.UserName\\My Documents\\My Pictures", but it doesn't work because it doesn't make "Environment.UserName" into the users user name. Is there any way to make this work.
Thanks for the help guys.
Last edited by vandel212; September 21st, 2009 at 02:53 PM.
- It's a long way to the top if you want to rock n' roll - AC/DC
Unfortunatly the users of this program do not have sufficient privlages to save files anywhere other than their documents. The reason I need to add this capability to my program is because the users name may have changed (ie. someone got married) so their log on info chaged but not how it is accessed in their my documents. I have no idea why my company would allow this but I don't care, I get paid at the end of the week regardless. Also It allows me to learn new things about programing. Hopefully that explained my needs for this a little better.
As a user, I would find it irritating to discover temporary files created by some application in the My Pictures folder. It seems surprising that a company would lock down the ApplicationData folder and break the functionality of many apps.
I tried doing it and what I would like to do is have a string in the settings that points to "C:\\Documents and Settings\\Environment.UserName\\My Documents\\My Pictures", but it doesn't work because it doesn't make "Environment.UserName" into the users user name. Is there any way to make this work.
Thanks for the help guys.
Code:
string path = string.Format(@"C:\Documents and Settings\{0}\My Documents\My Pictures", Environment.UserName);
string path = string.Format(@"C:\Documents and Settings\{0}\My Documents\My Pictures", Environment.UserName);
I'm sorry I don't understand, is this supposed to do this a design time or am I supposed to do this a run time, because putting it in the settings at design time didn't work.
Originally Posted by Arjay
As a user, I would find it irritating to discover temporary files created by some application in the My Pictures folder. It seems surprising that a company would lock down the ApplicationData folder and break the functionality of many apps.
Application Data would be a better place to save it, thanks for the tip. They didn't lock down anything in the users documents, so Application Data would still be a valid folder. Regardless I would still need to have settings to account for changed user names.
Last edited by vandel212; September 22nd, 2009 at 11:57 AM.
- It's a long way to the top if you want to rock n' roll - AC/DC
why not just use this? Then you don't have to worry about asking the user anything. the settings file is created in the Application Data folder for the current user. It doesn't matter what their user name is vs. what the user data folder's name is.
I. My question is, is there a way that I can take the users chosen directory and be able to use it again next time the program starts up? I would like to do this without creating another file in which I would store the information (i.e. create a text file with the directory path in it). .
try writing the folder path in registry or config file corresponding to the current user.. each time when you start up try reading this file.
Here you want to save data at system level and not at user level. Then you should not store data in any of user folders. You can designate some folder, on the root path of system-drive (or other drive). User should know where exactly that is stored. Provide the details in application itself (like 'Options'), or in documentation. If you are having deployment (setup), you can ask user where the data files should be stored.
You also save the location of data files in registry, so that you can refer from that location always. If user is changed, he/she can set the data-folder using 'Options' type of UI you may provide.
Here you want to save data at system level and not at user level. Then you should not store data in any of user folders. You can designate some folder, on the root path of system-drive (or other drive). ...
As much as I remembered he has told that this wasn't allowed by the firm which uses that program, or have I misduplicated what was written in an early post.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Here you want to save data at system level and not at user level. Then you should not store data in any of user folders. You can designate some folder, on the root path of system-drive (or other drive). User should know where exactly that is stored. Provide the details in application itself (like 'Options'), or in documentation. If you are having deployment (setup), you can ask user where the data files should be stored.
You also save the location of data files in registry, so that you can refer from that location always. If user is changed, he/she can set the data-folder using 'Options' type of UI you may provide.
As he stated, the user's don't have the privileges to create files outside of their user folders. and it's not something he can change.
Bookmarks