Hi guys... I am trainee in .net. I am currently trying to make web form notepad. For the save option I have used the save button on open and new page using the code as bellow but I am facing problem as the file is downloaded and the file with is saved are different. The downloaded file as shown in browser does not contain any content and the saved file contain the document. So I want to make the save file and downloaded file same. Can anyone solve my problem.
Thank you in Advance...
Code for save button....
protected void SaveButton_Click(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=document.txt");
StreamWriter sw = new StreamWriter("C:\\Users\\admin\\Desktop\\Downloads\\documents.txt");
sw.Write(TextBox1.Text);
sw.Close();
Response.End();
}
Francis SusaimichaelPosted Mar 3, 2015, 9:19 PM
protected void Button1_Click(object sender, EventArgs e)
{
StringWriter oStringWriter = new StringWriter();
oStringWriter.WriteLine(TextBox1.Text);
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment;filename=documents.txt");
Response.Clear();
// write the content in to the file
StreamWriter sw = new StreamWriter("C:\\documents.txt");
sw.Write(TextBox1.Text);
sw.Close();
// Write the same content into the response stream
using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8))
{
writer.Write(oStringWriter.ToString());
}
Response.End();
}