[RESOLVED] Store information within program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 34

Thread: [RESOLVED] Store information within program

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    112

    [RESOLVED] Store information within program

    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

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

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Store information within program

    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

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,197

    Re: Store information within program

    Why not write the temporary files in the proper location rather in the My pictures folder?

    See Environment.GetFolderPath( SpecialFolder.ApplicationData );

  4. #4
    Join Date
    Feb 2009
    Posts
    112

    Re: Store information within program

    Quote Originally Posted by Arjay View Post
    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.

    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
    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

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

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,197

    Re: Store information within program

    Quote Originally Posted by vandel212 View Post
    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.

    Check out http://msdn.microsoft.com/en-us/libr...istauac_topic6

    and look at the section titled Per-User Application Settings Locations.

  6. #6
    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 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);
    ===============================
    My Blog

  7. #7
    Join Date
    Feb 2009
    Posts
    112

    Re: Store information within program

    Quote Originally Posted by eclipsed4utoo View Post
    Code:
    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.

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

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

  8. #8
    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. #9
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: Store information within program

    Quote Originally Posted by vandel212 View Post
    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.

  10. #10
    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.

  11. #11
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    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

  12. #12
    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

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center