I don't understand the problem. File.AppendAllText() creates a file if it does not exist and appends the text (not a line).
This code will append the text, create the file if needed, and display the output after each write.
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmFile : Form
{
public frmFile()
{
InitializeComponent();
}
public static void AppendText(string FileName, string Buffer)
{
//I'm using another method here in case you want to log writes etc.
//It encapsulates the write process
File.AppendAllText(FileName, Buffer);
}
private void button1_Click(object sender, EventArgs e)
{
const string fName = @"C:\file3.txt";
string buffer = Guid.NewGuid().ToString(); //junk data
AppendText(fName, buffer);
Process p = Process.Start("notepad.exe", fName);
p.WaitForExit();
}
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
I added some modifications to Scott code
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmFile : Form
{
public frmFile()
{
InitializeComponent();
}
public static void AppendText(string FileName, string Buffer)
{
//I'm using another method here in case you want to log writes etc.
//It encapsulates the write process
File.WriteAllText(FileName, Buffer);
}
private void button1_Click(object sender, EventArgs e)
{
const string fName = @"C:\file3.txt";
string buffer = Guid.NewGuid().ToString(); //junk data
AppendText(fName, buffer);
Process p = Process.Start("notepad.exe", fName);
p.WaitForExit();
}
}
}
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
I'm glad you found a solution and good luck!
Please mark this thread as solved if your question has been answered.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Never mind Sknake:
I finally figured out what I was doing wrong. Your solution added to my code works perfectly. Thanks for the help!!
join our request for making sknake a featured poster then.(go to geeks lounge and you will see the thread "congritulations...", add something to support us)
i dont know what is wrong with the attachment that you couldnt open. maybe i have to set some password since our company does something when you attach something without a password which i think salts the contents or so.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127