473,323 Members | 1,537 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,323 software developers and data experts.

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 1957
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven O. | last post by:
I am basically a hobbyist programmer, at the moment doing a little work experimenting with some AI stuff. I learned C++, and then tried to teach myself MFC using MS Visual C++ 6.0. I swore off of...
12
by: Vibhajha | last post by:
Hi friends, My sister is in great problem , she has this exam of C++ and she is stuck up with some questions, if friends like this group provides some help to her, she will be very grateful....
3
by: Ross | last post by:
Hi I have bought the book 'Zen of CSS Design' but need some basic tips or links to start me off. I only have basic knowledge where I have set up styles in dreamwever like this ..this_style
18
by: free2cric | last post by:
Hi, I attanded an interview on C++ Question asked were and my answers to them.. 1. In a CPP program what does memory leak occure? -- i said.. In a constructor , the pointer variables were...
9
by: Rafael Charnovscki | last post by:
I can comprehend the basics of that subject (pointers, memory allocation, heap, stack etc), but I am interested to have references with more details. I have some C/C++ books and lots of URLs...
19
by: ash | last post by:
hi friends, i have some questions whch is in my last year question papers.i need some help to get logic of these questions. 1) write a C function, that takes two strings as arguments and...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
10
by: weird0 | last post by:
I heard of two c# interview questions that i still clearly don't know and havent understood the concept. One reason is also that I havent worked upon them 1. What is the difference between a...
17
by: liketofindoutwhy | last post by:
to simply add two quote images around some text. seems quite simple at first but turns out all the obvious solutions are not as desirable as a perfect solution: please see...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.