locked
C# 2010 desktop application on same computer RRS feed

  • Question

  • In an existing C#.net 2010 desktop application, I would need to have 2 users share the same computer. Both users will run the same desktop application but have access to different files and folders on the network share. Each person will have their own unqiue config file to show what files they have access to.

    Based upon what I have said, I have the following questions to ask:

    1. Will I need separate installs of the application on the same computer? Part of the install process includes placing the app.config file in the correct location. If so, can you tell me what I need to do for the separate installs?

    2. If I do not need separate installs, what should I do about the separate app.config files? Each person's config file will point to files they directly have access to. I do not want each person to access the other person's config file.

    Tuesday, October 13, 2015 2:34 PM

Answers

  • You only have 1 app.config that all users will share. You can set up each user to have their own user.config which is stored in a per-user directory. This is automatically handled by Windows and the CLR so you don't need to do anything other than specify which settings are per-user as documented in MSDN. They have a full example there for you to follow, just use Christopher's link.

    You can install an app per-user (aka ClickOnce) but if the only differences are related to config entries there really is no reason to.  The only benefit is that one user may upgrade to a newer version and the other may not. Doesn't sound like that applies here. However to install your app so that both users can use it then you need to either install as an admin (to install to Program Files) or you need to install into the public documents folder.  Most installers require admin privileges if they are for all users.  For ClickOnce this doesn't matter.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    • Proposed as answer by Kristin Xie Wednesday, October 14, 2015 6:45 AM
    • Marked as answer by midnight_car Wednesday, October 14, 2015 4:58 PM
    Tuesday, October 13, 2015 5:58 PM

All replies

  • I think you need to read up on application and user settings:

    https://msdn.microsoft.com/en-us/library/bb397750.aspx

    The primary rule is:
    If you want to write anything automatically, jsut put it in the User Profile folder. You never have to doubt you have write rights there.
    If you are not using an existing system, be sure to extract the path's via the SpecialFolders enumeration:

    https://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

    Tuesday, October 13, 2015 3:20 PM
  • 1. Will I need separate installs of the application on the same computer? Part of the install process includes placing the app.config file in the correct location. If so, can you tell me what I need to do for the separate installs?

    There is only one install, and both users can share the same program.

    2. If I do not need separate installs, what should I do about the separate app.config files? Each person's config file will point to files they directly have access to. I do not want each person to access the other person's config file.

    There is only one config file, you should be able to use <Appsettings> in the config file where you can separate user configurations in the <Appsettings> section by key, address the <Appsettings> by key using System.ConfigurationManager and address the settings based on the logged in user. 

    Tuesday, October 13, 2015 3:52 PM
  • Would you explain in more detail what you mean by,"There is only one config file, you should be able to use <Appsettings> in the config file where you can separate user configurations in the <Appsettings> section by key, address the <Appsettings> by key using System.ConfigurationManager and address the settings based on the logged in user.? 

    Are you saying that I would be able to use the same app.config file value for all users? if so, can you show me the code and or point me to a url that will show how to know what user is signed on and know which portion of the app.config file  that they would have access to?

    Tuesday, October 13, 2015 4:56 PM
  • http://www.thescarms.com/dotnet/AppSettings.aspx

    <copied>

    The config file is an XML file having the same name as your executable with an additional .config extension. The .NET Framework provides the

    <end>

    Note: the file is created from the app.config in the VS project, if this is a project the creates a desktop programname.exe. The file is called programname.exe.config that sits in the same location as the programname.exe after the solution is successfully compiled by VS. The  programname.exe.config must accompany the programname.exe and placed in the same location when the application  is deployed so that .NET can find the config file.

    • Proposed as answer by Kristin Xie Wednesday, October 14, 2015 6:45 AM
    Tuesday, October 13, 2015 5:37 PM
  • You only have 1 app.config that all users will share. You can set up each user to have their own user.config which is stored in a per-user directory. This is automatically handled by Windows and the CLR so you don't need to do anything other than specify which settings are per-user as documented in MSDN. They have a full example there for you to follow, just use Christopher's link.

    You can install an app per-user (aka ClickOnce) but if the only differences are related to config entries there really is no reason to.  The only benefit is that one user may upgrade to a newer version and the other may not. Doesn't sound like that applies here. However to install your app so that both users can use it then you need to either install as an admin (to install to Program Files) or you need to install into the public documents folder.  Most installers require admin privileges if they are for all users.  For ClickOnce this doesn't matter.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    • Proposed as answer by Kristin Xie Wednesday, October 14, 2015 6:45 AM
    • Marked as answer by midnight_car Wednesday, October 14, 2015 4:58 PM
    Tuesday, October 13, 2015 5:58 PM