简体   繁体   中英

Access ini file from documents for reading

I have put a config ini file "config.ini" for reading and writing to from my C# program, the thing is, if the user has UAC enabled then for some weird reasons the program doesn't read or write to the file but it managed to create the file but cannot read or write to it.

How can I get this to work.

this file is saved into DOCUMENTSFOLDER\\ProductName\\config.ini

Ini class file: http://www.sinvise.net/so/Ini.cs

Code Snippet of config.ini creation: http://www.sinvise.net/so/creation.txt

You should have better luck writing to the path: Environment.SpecialFolder.LocalApplicationData. Your app should have permission to write to that with UAC on or off, or even on machines where the app/user has very limited permissions.

Quick suggestion before going further, you should check out nini which is a neat INI handler and takes care of the reading/writing the INI files.

Sample usage of the code that reads from the ini file.

using Nini;
using Nini.Config;

namespace niniDemo{
   public class niniDemoClass{
       public bool LoadIni(){
            string configFileName = "demo.ini";
            IniConfigSource configSource = new IniConfigSource(configFileName);

            IConfig demoConfigSection = configSource.Configs["Demo"];
            string demoVal = demoConfigSection.Get("demoVal", string.Empty);
       }
   }

}

Try that and take it from there...

Hope this helps, Best regards, Tom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM