954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Write success message if file saves correctly...

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!

sastokes
Junior Poster in Training
50 posts since Oct 2011
Reputation Points: 10
Solved Threads: 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!

bill_kearns
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: