Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Casper Skovgaard

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Reading a text file with StreamReader


  private void ImportCountries()
  {
    string delimiter = ",";
    string fileName = @"c:\countrylist3.csv";

    StreamReader sr = new StreamReader(fileName);

    try
    {
      while (sr.Peek() >= 0)
      {
        string r = sr.ReadLine();
        string[] items = r.Split(delimiter.ToCharArray());
      }
    }
    finally
    {
      sr.Close();
    }
  }

Read connection string from web.config

web.config
<connectionStrings>
   <add name="ConnectionString" connectionString="Server=xxx; Port=3306; Database=xxx; uid=xxx; pwd=xxx;" />
</connectionStrings>



c#
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString

Read setting from web.config

Set the settings in web.config
<appSettings>
<add key="ResourcesPath" value="/Resources"/>
</appSettings>


How to read the settings in c#
string s = System.Configuration.ConfigurationManager.AppSettings["ResourcesPath"]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS