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!

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.