Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create text file but do not hard code the file and its path. I want use xml to read and write the file in Application.config.
So pls. help me out.
Posted
Comments
walterhevedeich 3-Jun-13 4:36am    
Perhaps you can also post what you have tried so far?

You may read/write the App.Config file using the ConfigurationManager class, see "ConfigurationManager Class" at MSDN[^] and the following CodeProject article: "Read/Write App.Config File with .NET 2.0"[^].
Creating and writing a text file is also well explained, see, for instance: How to: "Write to a Text File (C# Programming Guide)"[^].
 
Share this answer
 
Comments
johannesnestler 3-Jun-13 9:21am    
I think too that this is the correct way to read/write the App.config. Fiddling arround on XML level is for shure possible but I wouldn't do it...
Simple code to create a text file:
C#
string path = "D:\\Log.txt";             //path and name of the text file
StreamWriter objStreamWriter = new StreamWriter(path);
objStreamWriter.Write("Hi Welcome. . ."); // sting to write on the text file
objStreamWriter.Close();
 
Share this answer
 
You'll find this article here on CP about reading (and even writing) the application's configuration file: Read/Write App.Config File with .NET 2.0[^].

One of the ways to create a text file is to use the method System.IO.File.CreateText(String path)[^].

Regards,
— Manfred
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900