|
|
 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 16th, 2008, 05:25 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: Brentwood, CA, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
read any ".txt" file
Hi,
I am new to C# and trying to read in any .txt file that will be dropped in a directory, I will not have control of the file name.
Here is a sample of my calling code:
class Program
{
static void Main(string[] args)
{
FlatFileTo850 t = new FlatFileTo850();
string data = File.ReadAllText("C:\\src\\partner\\ConsoleApplica tion1\\subdir\\testFile.txt");
//would like to take out the file name "testFile.txt"
//and grab any .txt file
string result = t.Evaluate(ref data);
Console.WriteLine(result);
using (StreamWriter sw = new StreamWriter("TestFileXX.txt", true))
{
sw.Write(result.Replace("~", "~\r\n"));
}
Console.ReadLine();
}
}
Thanks in advance for any help.
Rod
|

November 16th, 2008, 06:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
|
|
You can use DirectoryInfo class and the GetFiles method, one overload accepts a search pattern, *.txt, off the top of my head, which will give you all text files. You can then read the data.
--
Joe ( Microsoft MVP - XML)
|

November 17th, 2008, 01:34 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Location: delhi, delhi, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
From DirectroyInfo to get path of directory and file path in FileINfo
and then use StreamReader to read any text file
|

November 18th, 2008, 01:07 PM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: Brentwood, CA, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your help, I was able get everything working!
Rod
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |