简体   繁体   English

从文档访问ini文件以进行阅读

[英]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. 我已经放置了一个config ini文件“ config.ini”,用于从我的C#程序中进行读写操作,问题是,如果用户启用了UAC,则出于某些奇怪的原因,程序不会对该文件进行读写操作设法创建了文件,但无法读取或写入文件。

How can I get this to work. 我怎样才能使它工作。

this file is saved into DOCUMENTSFOLDER\\ProductName\\config.ini 此文件保存到DOCUMENTSFOLDER \\ ProductName \\ config.ini

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

Code Snippet of config.ini creation: http://www.sinvise.net/so/creation.txt config.ini创建的代码段: http : //www.sinvise.net/so/creation.txt

You should have better luck writing to the path: Environment.SpecialFolder.LocalApplicationData. 您应该比较幸运地写路径: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. 您的应用应该有权在打开或关闭UAC的情况下进行写操作,甚至在应用/用户具有非常有限的权限的机器上也可以进行写操作。

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. 快速建议,然后再继续,您应该签出nini ,它是一个简洁的INI处理程序,并负责读取/写入INI文件。

Sample usage of the code that reads from the ini file. 从ini文件读取的代码的示例用法。

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. 希望这对您有所帮助,汤姆,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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