How can I select a folder or file from an asp.net web application?

I have an ASP.NET web application, and I need to put the data from the web page into an output text file. I would like to give the user the opportunity to choose the folder in which the file will be saved. For example, when a user clicks the Browse button, a folder selection dialog box appears.

Is it possible to implement such a thing in an asp.net web application?

Thanks,

Sergey

+6
source share
3 answers

EDIT:

Looking at your comment, I think you mean clicking on the response flow instead?

protected void lnbDownloadFile_Click(object sender, EventArgs e) { String YourFilepath; System.IO.FileInfo file = new System.IO.FileInfo(YourFilepath); // full file path on disk Response.ClearContent(); // neded to clear previous (if any) written content Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "text/plain"; Response.TransmitFile(file.FullName); Response.End(); } 

This should display a dialog box in the browser, allowing the user to choose where to save the file.

Do you want to use the FileUpload control

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx

 protected void UploadButton_Click(object sender, EventArgs e) { // Specify the path on the server to // save the uploaded file to. String savePath = @"c:\temp\uploads\"; // Before attempting to perform operations // on the file, verify that the FileUpload // control contains a file. if (FileUpload1.HasFile) { // Get the name of the file to upload. String fileName = FileUpload1.FileName; // Append the name of the file to upload to the path. savePath += fileName; // Call the SaveAs method to save the // uploaded file to the specified path. // This example does not perform all // the necessary error checking. // If a file with the same name // already exists in the specified path, // the uploaded file overwrites it. FileUpload1.SaveAs(savePath); // Notify the user of the name of the file // was saved under. UploadStatusLabel.Text = "Your file was saved as " + fileName; } else { // Notify the user that a file was not uploaded. UploadStatusLabel.Text = "You did not specify a file to upload."; } } 
+2
source share

Using <input type="file"> , the user can view files only on his computer. There is no way to see folders on the server unless you give it a list or tree structure so that it can select. Here is an example of building such a tree.

+3
source share

This download dialog is browser specific.

Look at common handlers with Response.Write, or even better write an Http handler for this purpose.

+1
source share

All Articles