473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1972
nal
1. Not sure what you exactly mean but if you are looking for the current
user, you can use System.Environm ent.UserName
2. Read Data from a file using StreamReader

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

using (System.IO.Stre amReader sr = new System.IO.Strea mReader(myFileP ath ))
{
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->Configuratio n 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.Configur ation.......... ....

"Eifel-benz" <Ei********@lyc os.de> wrote in message
news:A7******** *************** ***********@mic rosoft.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("kern el32")]

private static extern int GetPrivateProfi leString(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********@lyc os.de> wrote in message
news:A7******** *************** ***********@mic rosoft.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("kern el32")]

private static extern int GetPrivateProfi leString(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********@lyc os.de> wrote in message
news:A7******** *************** ***********@mic rosoft.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
309
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 MFC, which was a nightmare, and have been playing with Borlands C++ Builder. In C++ Builder, creating forms and other GUI elements is much...
12
2304
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. These are some questions:- 7. design and implement a class binsearch for a binary search tree.it includes search,remove and add options.make suitable...
3
1525
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
2486
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 assigned a memory block but the programmer forgets to free them in the destructor by usng delete operator. 2. ok, the delete operator is used .....
9
2010
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 "bookmarked", but all of them don't go too far on memory management as I would like. One of my main issues is whether function "main" and its local...
19
2070
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 returns a pointer to the first occurrence of 1st string in 2nd string or NULL if it is not present. -- i tried to solve it but it seems that i am not...
4
1843
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 it has now, after 15k lines of code resulted in a royal mess! It's my hope to ask some specific questions with scenario examples and that some of...
10
2114
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 reference and a pointer? Allah.... I don't even know what a reference is... 2. What are function pointers? 3. What are JOINS?
17
2049
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 http://www.0011.com/css/quote.html basically, Style 1 is just inlining the image, text, and image. Style 2 is using a table.
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.