PC Review


Reply
Thread Tools Rate Thread

c# code get category form ini file

 
 
nivedita
Guest
Posts: n/a
 
      31st Jul 2008
I get this information from http://techinterviewquestion.blogspot.com/
site. it works i used.

iniFileinfo.IniHelp ihelp = new iniFileinfo.IniHelp();

string iniFile="c://my.ini";
List<string> categories = ihelp.GetCategories(iniFile);
foreach (string category in categories)
{
Console.WriteLine(category);
}

Out put :-
serverpath
localpath

File my.ini [serverpath] files=solaris9 operator=mmas [localpath]

iniFileinfo.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace iniFileinfo
{
using System;
using System.Runtime.InteropServices;
using System.Text;
class IniHelp
{
[DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringW",
SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
string lpReturnString,
int nSize,
string lpFilename);
[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW",
SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFilename);
public List<string> GetCategories(string iniFile)
{
string returnString = new string(' ', 65536);
GetPrivateProfileString(null, null, null, returnString, 65536,
iniFile);
char[] sep = {'\0'};
List<string> result = new List<string>(returnString.Split(sep));
result.RemoveRange(result.Count - 2, 2);
return result;
}
public List<string> GetKeys(string iniFile, string category)
{
string returnString = new string(' ', 32768);
GetPrivateProfileString(category, null, null, returnString, 32768,
iniFile);
char[] sep = { '\0' };
List<string> result = new List<string>(returnString.Split(sep));
result.RemoveRange(result.Count - 2, 2);
return result;
}
public string GetIniFileString(string iniFile, string category, string
key, string defaultValue)
{
string returnString = new string(' ', 1024);
GetPrivateProfileString(category, key, defaultValue, returnString,
1024, iniFile);
char[] sep = { '\0' };
return returnString.Split(sep)[0];
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can't create form in code-behind file Dan Microsoft ASP .NET 0 26th May 2006 11:16 AM
Open a pdf file from code in my form Tom Ross Microsoft Access Form Coding 3 16th Dec 2005 12:35 PM
c++ code ending up in form.h file Peted Microsoft VC .NET 1 14th Aug 2005 04:45 PM
Category and Sub-Category in the Contact form Paul Microsoft Outlook Form Programming 1 2nd Oct 2004 12:53 AM
Can I color code tasks by category? Brandi Microsoft Outlook 1 22nd Jun 2004 05:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:27 AM.