Does C# have a class for handling properties files?

Asked

Viewed 459 times

6

In C# has some class for handling files properties? In Java I use the class Properties, I was wondering if you have a C equivalent#?

  • 1

    What does this class do in Java? Cite examples

  • What kind of file is this?

  • This article explains the properties files in java http://www.devmedia.com.br/utilizando-arquivos-de-propriedades-no-java/25546 and wanted to know if you have in c#

  • @viniciusafx think q vc will have to make your own ini file to store configuration data. I couldn’t find C# support for manipulating this file type.

3 answers

4


There are some libraries that allow to do something very sophisticated. I wouldn’t know to specify a specific.

There is something a little different in the standard library, it would be the class ConfigurationManager.

Has a response in the OS with an example trying to reproduce the basis of this class in C#.

  • While I was waiting for answers here, I decided to create a project to solve this, and when I finished I saw that it was very similar to the example you mentioned, but let it be clear that I did not copy. Link to my project: https://github.com/viniciusafx/Properties/blob/master/Properties/Properties.cs

  • For me it would be indifferent if you copied it. I’m glad you’re on the path you want.

4

I’m a Java layman, but I believe you’re talking about storing "configuration" information and/or miscellaneous information in one location to be "consumed" when necessary.

In C# there are some ways to do this, but the most correct is:

Web Applications: Filing cabinet Web.config

Web.config is a special file, similar to . htaccess used by Apache, which configures the behavior of your application. Created with XML format can be easily edited with a common editor, such as notepad.

Web.config is usually used to store values and parameters that are common throughout the application.

However, every web application created can have its own web.config file, and the information in this file is valid for the current directory and its subdirectories.

source

There is a "section" within the Web.config calling for appSettings which is used to "store" information that can be "accessed" later.

Ex.:

  <appSettings>
    <add key="NomeSistema" value="Meu sistema" />
    <add key="UrlLocalhost" value="http://localhost" />
    <add key="UrlSite" value="http://meusite.com.br" />
    <add key="defaultCulture" value="pt-BR" />
  </appSettings>

If necessary add the Assembly reference:

using System.Configuration;

To access the data:

label.Text = ConfigurationManager.AppSettings["NomeSistema"];

Desktop Applications: Filing cabinet App.config

Same thing as in the web application:

Ex.:

  <appSettings>
    <add key="NomeSistema" value="Meu sistema" />
    <add key="UrlLocalhost" value="http://localhost" />
    <add key="UrlSite" value="http://meusite.com.br" />
    <add key="defaultCulture" value="pt-BR" />
  </appSettings>

If necessary add the Assembly reference:

using System.Configuration;

To access the data:

return ConfigurationManager.AppSettings["NomeSistema"];

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.