469,649 Members | 1,241 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Some easy Questions about C#

I'm working the first days with Visual C#.net. So most of you think these questions are really easy.

1. How can I read out the windows-account?
2. How can I read datas from an INI-file?

A short example will help me quiet good.

Thanks.
Nov 16 '05 #1
3 1858
nal
1. Not sure what you exactly mean but if you are looking for the current
user, you can use System.Environment.UserName
2. Read Data from a file using StreamReader

string myFilePath = @"C:\myfile.ini";
string myFileText = string.Empty;

using (System.IO.StreamReader sr = new System.IO.StreamReader(myFilePath ))
{
myFileText = sr.ReadToEnd();
sr.Close();
}

Your specifics may be different, you may be reading line by line, which is
equally simple. B the way if you want to store settings for your application
you'd probably be better off creating a configuration file...by using
Add->Configuration File to your project, which will create an app.config
file, which is nothing but an xml file that can be read easily, using
System.Configuration..............

"Eifel-benz" <Ei********@lycos.de> wrote in message
news:A7**********************************@microsof t.com...
I'm working the first days with Visual C#.net. So most of you think these questions are really easy.
1. How can I read out the windows-account?
2. How can I read datas from an INI-file?

A short example will help me quiet good.

Thanks.

Nov 16 '05 #2
You could use a WIN32 API call in your class.

Add:
using System.Runtime.InteropServices;

And at the top of the class define the WIN32 function and the DLL in which
it is carried:
[DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section,

string key,string def, StringBuilder retVal,

int size,string filePath);

Now you can read the INI file like you did in C or C++.

HTH

Harry

"Eifel-benz" <Ei********@lycos.de> wrote in message
news:A7**********************************@microsof t.com...
I'm working the first days with Visual C#.net. So most of you think these questions are really easy.
1. How can I read out the windows-account?
2. How can I read datas from an INI-file?

A short example will help me quiet good.

Thanks.

Nov 16 '05 #3
Thanks for your help. But there is still a problem. I didn't programm reading an INI-file in c/c++ or in any programming language else. So I don't know how to do that.

"Harry Whitehouse" wrote:
You could use a WIN32 API call in your class.

Add:
using System.Runtime.InteropServices;

And at the top of the class define the WIN32 function and the DLL in which
it is carried:
[DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section,

string key,string def, StringBuilder retVal,

int size,string filePath);

Now you can read the INI file like you did in C or C++.

HTH

Harry

"Eifel-benz" <Ei********@lycos.de> wrote in message
news:A7**********************************@microsof t.com...
I'm working the first days with Visual C#.net. So most of you think these

questions are really easy.

1. How can I read out the windows-account?
2. How can I read datas from an INI-file?

A short example will help me quiet good.

Thanks.


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Vibhajha | last post: by
3 posts views Thread by Ross | last post: by
18 posts views Thread by free2cric | last post: by
9 posts views Thread by Rafael Charnovscki | last post: by
19 posts views Thread by ash | last post: by
10 posts views Thread by weird0 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.