Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a sort of history in my programm wich, documents what the programm
is currently doing.

Now i want to create a textfile on first run, into the exe folder to write
this documentation every time into this file.

I am using a class for writing the documentation into a rich textbox.
the method of the class wich perform this documentation is looking like this:

C#
public void Aktual(int number)
{
switch(number)
{
case 1:
string Text1 = "Hi im text1, this is currently doing";
break;

//And further
}
}


so my problems are:

- Creating a textfile into exe folder
SOLVED: (- Write in general into this existing file, to dont overwrite)
SOLVED: (- Open this existing textfile to view it)


Thank you

ps.: Let me know if you need more explanation

greets Niko
Posted
Updated 15-Nov-12 20:31pm
v2

if your just trying to write to the end of your existing file this should help, you need to use streamreader and streamwriter one of the parameters in the streamwrite lets you specify where you want to save the file

[Link]
 
Share this answer
 
Do not write into the program folder! Use the "ProgramData" folder instead. You can get it via Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData). Create subfolders for your company, and for your program.
If logging should be per user, you can use the same structure in Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).
 
Share this answer
 
 
Share this answer
 
Comments
niko_tells 16-Nov-12 3:13am    
And how to open this File? Cause File.Open doesnt really do something..
Jacques Loubser 16-Nov-12 3:30am    
System.IO.StreamReader sr = new System.IO.StreamReader("TestFile.txt");
String line = sr.ReadToEnd();
//Do whatever with the output
sr.Close();
niko_tells 16-Nov-12 3:15am    
System.Diagnostics.Process.Start(Path);

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