简体   繁体   English

从配置文件启动字符串

[英]initiating a string from a config file

I am asked to do this and I have no clue from where to start since I am new to it. 我被要求这样做,因为我是新手,所以我不知道从哪里开始。

I have created a C# .NET application (a web api to be more precise) using Visual Studio 2012. 我已经使用Visual Studio 2012创建了一个C#.NET应用程序(更准确地说是一个Web API)。

I created an lsi file ( the new version of msi files) to be able to deploy it on a server. 我创建了一个lsi文件(msi文件的新版本)以能够将其部署在服务器上。

Now I want to create some sort of a configuration file where I can edit a string without having to go into the code every time to change it every time. 现在,我想创建某种配置文件,在其中可以编辑字符串,而不必每次都进入代码来每次更改它。

lets say the variable is called mystring : 1- how can I create a config file that request a string without having to go into the code? 可以说该变量称为mystring :1-如何创建一个无需字符串即可请求字符串的配置文件? 2- how can I say the mystring=input string ? 2-我怎么能说mystring = input字符串?

I tried to look it up but since I don t have the exact name I don t really know what I am searching for ... 我试图查找它,但是由于我没有确切的名字,所以我真的不知道我要搜索的内容...

Thanks, 谢谢,

One solution would be to save a configuration file with the settings you want to load, I'd suggest saving it to the ProgramData folder. 一种解决方案是使用您要加载的设置保存配置文件,建议将其保存到ProgramData文件夹中。

I would save the settings to an XML file (or JSON) so you can serialize and deserialize the data into your program when it loads. 我会将设置保存到XML文件(或JSON)中,以便在加载程序时可以对数据进行序列化和反序列化。 Guide 指南

You can also save other details so they'll persist each time the application is opened this way, such as a username field. 您还可以保存其他详细信息,以便每次以这种方式打开应用程序时它们都将保留下来,例如用户名字段。

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

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