Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Text
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:
 
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 15-Nov-12 20:18pm
Edited 15-Nov-12 20:31pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi
 
This should help
 
http://msdn.microsoft.com/en-us/library/as2f1fez.aspx[^]
 
Jacques
  Permalink  
Comments
niko_tells at 16-Nov-12 3:13am
   
And how to open this File? Cause File.Open doesnt really do something..
Jacques Loubser at 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 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100