hi I want to read a text file without giving pathname which may be saved in any drive.
how to read a text file dynamically?hi I want to read a text file without giving pathname which may be sav
Page 1 of 1
5 Replies - 2301 Views - Last Post: 30 January 2009 - 10:15 AM
Replies To: how to read a text file dynamically?
#2
Re: how to read a text file dynamically?
Posted 28 January 2009 - 11:26 PM
Well a path is required, how else if it going to know where the file is?
#3
Re: how to read a text file dynamically?
Posted 28 January 2009 - 11:37 PM
thanks for reply but i want to give only file name not to give pathname.is it possible in this way? Can i have to first search the file hence i should read the file.
This post has been edited by priks_24: 28 January 2009 - 11:52 PM
#4
Re: how to read a text file dynamically?
Posted 29 January 2009 - 05:14 AM
If you're doing it like:
You could for example fill in "File.php" and it'll read from the file "File.php" in the same path as the executable.
Or:
Will read the file "File.php" (or any other inserted file) in the folder "files".
I hope this somewhat solved your question.
string path = Console.ReadLine(); StreamReader strRdr = new StreamReader(path);
You could for example fill in "File.php" and it'll read from the file "File.php" in the same path as the executable.
Or:
string path = Console.ReadLine();
StreamReader strRdr = new StreamReader("files/" + path);
Will read the file "File.php" (or any other inserted file) in the folder "files".
I hope this somewhat solved your question.
#5
Re: how to read a text file dynamically?
Posted 30 January 2009 - 05:54 AM
Thanks Kirth,
my coding is
how can i read this text file without giving path i mean dynamically.
my coding is
try
{
using (StreamReader sr = new StreamReader("C:/Documents and Settings/abc/Desktop/connection.txt"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
listBox1.Items.Add(line);
}
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
how can i read this text file without giving path i mean dynamically.
This post has been edited by Jayman: 30 January 2009 - 10:13 AM
#6
Re: how to read a text file dynamically?
Posted 30 January 2009 - 10:15 AM
Store the file in the same folder as the executable program. Then you will not need to supply the path to the file, you can simply reference it by name and extension.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|