Access ini file from documents for reading

≯℡__Kan透↙ 提交于 2019-12-31 05:55:10

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2125491/access-ini-file-from-documents-for-reading

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!