![]() |
Readline
Hi,
I always get stuck when I try to do readlines. I am writing a program that is suppose to open a file when you click on open file, then the file that it opens should read the first part and do a item add to a combo box. Any help would be appreciated. If you need more info please let me know. Thanks, Rachel |
Re: Readline
System.IO.File.ReadAllLines("./myfile.ext")[0]
Read the .NET API docs, and perhaps bookmark the page: http://msdn2.microsoft.com/en-us/library/ms229335.aspx |
Re: Readline
Thank you :)
Yes, I understand it could be done this way...but how would I do it if I don't know the name of the file? The user has to pick the file and when they hit "Ok" the file should be read. Rachel |
Re: Readline
You'd need to use an open file dialog box.
MSDN have an excellent tutorial video series on this sort of stuff. Go to this URL: http://msdn2.microsoft.com/en-us/vstudio/aa700732.aspx and then scroll down to the bottom of the page. From memory, dialog controls are covered in Lesson 4. Regards, Matt. I |
Re: Readline
Right. I am using an open dialog box. But once the file is opened I don't know how to read the file to put the first part of the text into a combo box. The code should read the text line by line and put only the first part into a combo box so that when the arrow is selected you should see a choice of 100, 200, 300, etc...
I'll go to the link. I have tried these tutorials, but they do not go into great detail. I hope this one does. Thanks, Rachel |
Re: Readline
The other thing that you could benefit from is probably getting a good book. There are loads around and if you want detail are probably much better than most tutorials on the internet.
|
Re: Readline
Instead of hard coding the filename (
System.IO.File.ReadAllLines("./myfile.ext")[0]) just use the dialog's filename property after displaying it. E.g.:
if(openFileDialog1.ShowDialog() == DialogResult.OK ) |
| All times are GMT -5. The time now is 4:02 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC