0

I have code for a browse button and I wanted to know how to write the code to output a sucess message if it saves correctly.

Also how to output the file path to a textbox...

here is the code I have so far...

protected void Browse_Click(object sender, EventArgs e)
        {
            string FileName = "ExporterOutput.txt";
            string FilePath = "C:/Users/oZ012D/My Documents/ExporterOutput.txt";
            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = "text/plain";
            response.AddHeader("Content-Disposition", "attachment; filename = " + FileName + ";");
            response.TransmitFile(FilePath);
            response.Write("Username:");
            response.Write(username.Text);
            response.Write("  ");
            response.Write("Authorization Level:");
            response.Write(authlvl.Text);
            response.Write("  ");
            response.Write("Database:");
            response.Write(DropDownList1.Text);
            response.Write("  ");
            response.Write("Dataset:");
            response.Write(DropDownList2.Text);
            response.Write("  ");
            response.Write("SGMLid:");
            response.Write(sgml.Text);
            response.Flush();
            response.End();
        }

Thank you!

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by bill_kearns
0

You want to look into the File class of the System.IO namespace and here is a link to get you started. http://msdn.microsoft.com/en-us/library/system.io.file.aspx

Then in regards to how to get it done, try this.

string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
	try
	{
		// Create a file to write to.
		using (StreamWriter sw = File.CreateText(path))
		{
			sw.WriteLine("Hello");
			sw.WriteLine("And");
			sw.WriteLine("Welcome");
		}
		Lable1.Text = "Success!";
	}
	catch(Exception e)
	{
		// put your error handling here.
		Lable1.Text = "Save Failed! - " + e.Message;
	}
}

Hope that helps!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.