473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

c# code get category form ini file

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<stringcategories = 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<stringGetCategories(string iniFile)
{
string returnString = new string(' ', 65536);
GetPrivateProfileString(null, null, null, returnString, 65536,
iniFile);
char[] sep = {'\0'};
List<stringresult = new List<string>(returnString.Split(sep));
result.RemoveRange(result.Count - 2, 2);
return result;
}
public List<stringGetKeys(string iniFile, string category)
{
string returnString = new string(' ', 32768);
GetPrivateProfileString(category, null, null, returnString, 32768,
iniFile);
char[] sep = { '\0' };
List<stringresult = 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];
}
}
}
Jul 31 '08 #1
0 1232

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Code is as follows: document.write('<FORM name="horseform">'); document.write(' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size: 8pt">'); document.write(' <OPTION...
1
by: Dave Elliott | last post by:
I have a form named Add Products where I enter Products with a Category ID, Category Name & Category Description. I want the form to open showing only the records assocated with the Category Labor...
2
by: rcmail14872 | last post by:
I have a form that lists several different categories for labels. I made a form that will let the user add a new category. On the Form the user can type in the name for the new category, then I...
6
by: benb | last post by:
I have form that looks a lot like a search bar for the user to search for records matching specified criteria (e.g. first names containing "ben"). For robust results, an intermediary form displays...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
4
by: robinsand | last post by:
Header File: car.h #if !defined CAR_H #define CAR_H enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV }; class Car { public: Car();
3
by: webandwe | last post by:
Hi, the following coding is and the whole of the admin, it uploads images you select to the folder called images: But the problem is is sets the images permissions to 600 and I need them to be 644...
3
by: zufie | last post by:
I am trying to fix the following VBA code from an MS Access database I inherited. I conclude with an example of one of the symptoms resulting from this VBA code: Option Compare Database...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.