CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 34
  1. #16
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Store information within program

    Quote Originally Posted by JonnyPoet View Post
    Dont do this is the Properties itself ! Do this where your code wants to read the UserPath
    Simple instead of accessing the Properties
    Code:
    string userpath = Properties.Settings.Default.UserPath;
    // do
    string userpath =  string.Format(@"C:\Documents and Settings\{0}\My Documents\My Pictures", Environment.UserName);
    No need to have that code in the Properties. !!
    he can't use Environment.UserName in the path. The Environment.UserName can be different from the user name in the path(look at his example a couple of posts up).

    Once thing you could do is get each subdirectory in the C:\Documents and Settings directory, then parse the string to see if that matches the first name of the current user(since you can't use the last name). I don't know how your company works, but at mine, I am the only user(other than administrator) on my PC. So in the C:\Documents and Settings directory on my PC, there are only two folders.
    ===============================
    My Blog

  2. #17
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Store information within program

    Quote Originally Posted by eclipsed4utoo View Post
    he can't use Environment.UserName in the path. The Environment.UserName can be different from the user name in the path(look at his example a couple of posts up).
    I see. In that case I would try to find the folder by my program using an address written into the Properties.Settings.Default.DataPath, but if the name has changed and it cannot be found, then I simple would pop up a small Setup form where the user can input the new place where the file is located now. And storing that new location in the properties again.
    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

  3. #18
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Store information within program

    Quote Originally Posted by JonnyPoet View Post
    I see. In that case I would try to find the folder by my program using an address written into the Properties.Settings.Default.DataPath, but if the name has changed and it cannot be found, then I simple would pop up a small Setup form where the user can input the new place where the file is located now. And storing that new location in the properties again.
    or could use the FolderBrowseDialog and let the user choose what their user folder is.
    ===============================
    My Blog

  4. #19
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Store information within program

    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.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #20
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Store information within program

    Quote Originally Posted by eclipsed4utoo View Post
    or could use the FolderBrowseDialog and let the user choose what their user folder is.
    Yep but let the user the possibility to use FolderBrowser or textbox as well, as there maybe some connections when you have a network, where the Folderbrowser cannot show the directories of the server and you need to type it by hand..
    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

  6. #21
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Store information within program

    Quote Originally Posted by Ajay Vijay View Post
    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

  7. #22
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Store information within program

    Quote Originally Posted by Ajay Vijay View Post
    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.
    ===============================
    My Blog

  8. #23
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Store information within program

    Quote Originally Posted by Shuja Ali View Post
    You can use settings in C# to store information pertaining to the application.
    Take a look at http://msdn.microsoft.com/en-us/libr...69(VS.80).aspx
    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.
    ===============================
    My Blog

  9. #24
    Join Date
    Feb 2009
    Posts
    112

    Re: Store information within program

    Quote Originally Posted by JonnyPoet View Post
    Dont do this in the Properties itself ! Do this where your code wants to read the UserPath
    Simple instead of accessing the Properties
    Code:
    string userpath = Properties.Settings.Default.UserPath;
    // do
    string userpath =  string.Format(@"C:\Documents and Settings\{0}\My Documents\My Pictures", Environment.UserName);
    No need to have that code in the Properties. !!
    I understand what you are saying about using the Environment.UserName to find the appropriate path, but as I've explained in my last post this doesn't work 100% of the time in my situation. I've had my code setup simlar to that before I even started this thread and it blew up when the directory did not exist. Now I have my program look to see if the path exists and if it does not it makes the user locate their "My Documents" and from there it finds the Application Data folder. Then it needs to save the file path into the settings because if it didn't, it would ask the user to locate their my documents every time the program ran.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

  10. #25
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Store information within program

    Quote Originally Posted by vandel212 View Post
    .... it blew up when the directory did not exist. Now I have my program look to see if the path exists and if it does not it makes the user locate their "My Documents" and from there it finds the Application Data folder.
    Then simple use a try -catch block and if you get an exception because the path doesn't exist you open the setup form and let the user choose his new path by that.
    Ot use what eclipsed4utoo and Suhja Ali already suggested because thats possible in any case and doesn't need any username.
    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

  11. #26
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Store information within program

    Just use the application data code that I posted in #3, check for the existence of the path (Directory.Exists) and if the path doesn't exist, create it (Directory.Create).

    Note: this won't cover the case if a user has a name change (such as getting married); however, that would the responsibility of the network admin to properly migrate the user's settings in this case.

    If the network admin doesn't migrate the settings, then your program should just recreate the default settings (by checking for existence of the file with File.Exists). There is no need to prompt the user for the old settings because most likely they won't know where to find them anyway (or a network admin may have wiped them out).

  12. #27
    Join Date
    Feb 2009
    Posts
    112

    Re: Store information within program

    Quote Originally Posted by Arjay View Post
    Just use the application data code that I posted in #3, check for the existence of the path (Directory.Exists) and if the path doesn't exist, create it (Directory.Create).

    Note: this won't cover the case if a user has a name change (such as getting married); however, that would the responsibility of the network admin to properly migrate the user's settings in this case.

    If the network admin doesn't migrate the settings, then your program should just recreate the default settings (by checking for existence of the file with File.Exists). There is no need to prompt the user for the old settings because most likely they won't know where to find them anyway (or a network admin may have wiped them out).

    I agree the network admin should migrate the settings, but I don't think that is going to happen anytime soon. Creating the directory is a good solution but the problem lies with that they might not have sufficient privliges to create that directory. So prompting the user for their my documents folder is the only solution I could think of. I thought about the whole user finding their name in the documents and settings as well and I figured that if they weren't familiar enough with computers they wouldn't know where to find it. However finding 'My Documents' is pretty basic, so I have them find their My Documents and then manipulate the string to get the user's username. Because when the Folder Browser Dialog box comes up, the My Documents is the second or third folder on the list by default, so it's hopefully easy for them to figure out.

    I think I got this working so I appreciate the help thank you very much.
    Last edited by vandel212; September 28th, 2009 at 12:45 PM.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

  13. #28
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Store information within program

    Quote Originally Posted by vandel212 View Post
    I agree the network admin should migrate the settings, but I don't think that is going to happen anytime soon. Creating the directory is a good solution but the problem lies with that they might not have sufficient privliges to create that directory. So prompting the user for their my documents folder is the only solution I could think of. I thought about the whole user finding their name in the documents and settings as well and I figured that if they weren't familiar enough with computers they wouldn't know where to find it. However finding 'My Documents' is pretty basic, so I have them find their My Documents and then manipulate the string to get the user's username. Because when the Folder Browser Dialog box comes up, the My Documents is the second or third folder on the list by default, so it's hopefully easy for them to figure out.

    I think I got this working so I appreciate the help thank you very much.
    In my opinion, that is still a lot of work when there is an option available to do everything automatically without the user ever having to tell you anything.

    But you got it work, so we have success.
    ===============================
    My Blog

  14. #29
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Store information within program

    Quote Originally Posted by vandel212 View Post
    I agree the network admin should migrate the settings, but I don't think that is going to happen anytime soon. Creating the directory is a good solution but the problem lies with that they might not have sufficient privliges to create that directory.
    There seems to be a disconnect here. You've already agreed that the ApplicationData directory is not locked down by the system admins, right? And since Windows allows programs to create files and directories underneath the ApplicationData directory, you are going to be good to go. There isn't any need to make this harder than it needs to be. IMO, prompting the user isn't a good solution because most users won't have any idea where to put these files and will become concerned when they see temporary files appear in their My Documents folders. Why not follow the Windows application compatibility guidelines and store the app data in the correct location?

  15. #30
    Join Date
    Feb 2009
    Posts
    112

    Re: Store information within program

    Quote Originally Posted by Arjay View Post
    There seems to be a disconnect here. You've already agreed that the ApplicationData directory is not locked down by the system admins, right? And since Windows allows programs to create files and directories underneath the ApplicationData directory, you are going to be good to go. There isn't any need to make this harder than it needs to be. IMO, prompting the user isn't a good solution because most users won't have any idea where to put these files and will become concerned when they see temporary files appear in their My Documents folders. Why not follow the Windows application compatibility guidelines and store the app data in the correct location?
    I see what you are saying, I'll have to check out if I can save to the users new account documents and settings folder. I looked at one of those examples where the person's name changed and it wouldn't work with Environment.UserName. The person did not have anything in the new user account's documents and settings folder, although I did not try to save anything to it. However, I did take your advice and the files are stored in application data now. It is not putting anything in the My Documents folder it's just taking "C:\Documents and settings\jane.smith\My Documents" and turing it into "C:\Documents and Settings\jane.smith\Application Data\Program Name" by removing 'My Documents' and replacing it with 'Application Data\Program Name'.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured