Skip Navigation Links.

Northwind\General\IniFile.cs

D:\Temp3\TestProjects\CSADO.Net\Northwind\General\IniFile.cs
/*
 * This file was generated by ProCG version 2.0
 *
 * File name:	Northwind\General\IniFile.cs
 * Language:	C# - ADO.Net 
 * Database:	My Sql
 *
 * Copyright (c) 2002-2019 iGenXSoft.
 * For more information visit http://www.igenxsoft.com
 */


using System;
using System.Collections.Generic;
using System.IO;

namespace Northwind.General
{
	/// <summary>
	/// Summary description for IniFile.
	/// </summary>
	public class IniFile
	{
		protected string m_FileName;
		
		public IniFile(string fileName)
		{
			m_FileName = fileName;
		}

		public Dictionary<string,string> GetAllFromFile()
		{
			Dictionary<string,string> hashTable = new Dictionary<string,string>();

			if (m_FileName == null || m_FileName == "")
				throw new Exception("File Name for IniFile wasn't set");

			if (File.Exists(m_FileName))
			{
				// Create an instance of StreamReader to read from a file.
				// The using statement also closes the StreamReader.
				using (StreamReader sr = new StreamReader(m_FileName)) 
				{
					string line;
	
					// Read and display lines from the file until the end of 
					// the file is reached.
					while ((line = sr.ReadLine()) != null) 
					{
						if (line == "") continue; 
						string [] tokens = line.Split(new char[] {'\t'}); 
						System.Diagnostics.Debug.Assert(tokens.GetLength(0)==2);
						hashTable.Add(tokens[0],tokens[1]);
					}
				}
			}
			return (hashTable);
		}

		public void SetToFile( Dictionary<string,string> hashTable)
		{
			string line;
			using (StreamWriter sw = new StreamWriter(m_FileName)) 
			{
				foreach (KeyValuePair<string,string> de in hashTable) 
				{
					line = de.Key + "\t" + de.Value;
					sw.WriteLine(line);
				}
			}
		}
	}
}


  //      1830 ProCG uses this line - don't edit it