473,399 Members | 3,832 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,399 software developers and data experts.

Reading parameters from .ini file using C#.NET

Hi All,

Is that possible to read parameters from .ini file using C#.NET. Could you give some idea or example. Pls advise me.

Thanks
Seenu
Oct 22 '07 #1
3 2659
yes it is possible to do so...
please search on the web u may find it.............
Oct 23 '07 #2
Expand|Select|Wrap|Line Numbers
  1. C# .Net
  2.  
  3.         [DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringA",
  4.             //BestFitMapping=true,
  5.             //PreserveSig=false,
  6.             //ThrowOnUnmappableChar=true,
  7.             SetLastError = true,
  8.             CharSet = CharSet.Ansi,
  9.             ExactSpelling = true,
  10.             CallingConvention = CallingConvention.StdCall)]
  11.  
  12.         public static extern int GetPrivateProfileString(
  13.           string lpAppName,
  14.           string lpKeyName,
  15.           string lpDefault,
  16.           StringBuilder lpReturnString,
  17.           int nSize,
  18.           string lpFilename);
  19.  
  20. public string GetValue(string strSection, string strKey, string strDefault, string strFile)
  21.         {
  22.                         string strRetVal;
  23.             int intLength;
  24.             StringBuilder strReturnString = new StringBuilder(1024);
  25.  
  26.             try
  27.             {
  28.                 intLength = cShared.GetPrivateProfileString(strSection, strKey, "", strReturnString, 256, m_strDirFile);
  29.  
  30.                 strRetVal = cShared.Left(strReturnString.ToString() , intLength);
  31.                 strRetVal = strRetVal.Replace( (char)0, ' '); //removes trailing Ascii 0's especially in 2-byte gets
  32.  
  33.                 if ((strRetVal.Length ) == 0 & (strDefault.Length != 0) )
  34.                 {
  35.                     SetValue(strSection, strKey, strDefault);
  36.                     strRetVal = strDefault;
  37.                 }
  38.                 return (strRetVal);
  39.              }
  40.  
  41.             catch(Exception ex)
  42.             {
  43.                 return ex.Message;
  44.             }
  45.         }
  46.  
  47.  
Oct 24 '07 #3
Plater
7,872 Expert 4TB
Wouldn't it be just as usefult to use the .net's own built in system for storing persistant values?
The properties/settings thing allows that.
Oct 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alexander Schmidt | last post by:
Hi, I am not very familiar with C++ programming, so before I do a dirty hack I ask for a more elegant solution (but only the usage of STL is allowed, no special libs). So I need to read a file...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
2
by: Tomas Kepic | last post by:
Hi all, I want read some data stored in XML document in my aspx page, but I have problem with this. My XML file settings.xml is: <?xml version="1.0" encoding="utf-8" ?> <parameters>
2
by: news.microsoft.com | last post by:
Hi After conducting a several searches, I wasn't sure where to post this question. So my apologiesbefore hand for double posting this and possibly posting to the wrong forum(s). Okay, I have...
3
by: Sridhar | last post by:
Hi, I need to read a pdf file which is on my hard drive and put it in the sql server database. Once placed in the sql server, I again need to read that file from the database and display it on...
29
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
21
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing...
1
by: dim505 | last post by:
Hi friends, I want to open an autocad file using C# program in asp.net and read the parameters of that .dwg file.I could able to open the .dwg file but dont know how to read the parameters like...
2
by: cluce | last post by:
I am trying to read a csv file with user info (username, password, email, address, city, zip, state, etc.) I am inserting the username, password, email into the aspnet_memberhsip table using the...
5
by: NitinSawant | last post by:
Hello, I'm beginner to php (actually i'm java/jsp developer), What i'm trying to do is Accept parameters from the HTML file and write them to a newly created file using php, I wrote...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.