Infinity
Infinity

Reputation: 1325

c#.net website - How to let user choose a folder?

I basically want to open a dialog box on the click of a button..The user will choose a destination folder and then a text file will be created in the chosen Folder using the path in the dialogue box.

I have used asp.net's FileUpload to upload files but I don't know how to chose a folder using it. Or there's some other way to do this? please help . Thanks.

Upvotes: 0

Views: 9028

Answers (2)

Tory Netherton
Tory Netherton

Reputation: 753

The browser won't normally let you access the users drive directly. It's a security issue. So as was said earlier, you normally just send the file to the users browser and they/it decide where to save it etc.

What you're trying to do could probably be done using java or silverlight, etc. I doubt you want to have to go there though.

Is there some reason you can't just send the file to them and let them / their browser decide how to save it just like is normally done with file downloads?

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

The only way you can be writing to a folder on the user computer is by having the user click on a button and then your server would send the file and the user will be prompted for where he wants to save it:

public void BtnDownload_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.ContentType = "text/plain";
    Response.AppendHeader("Content-Disposition", "attachment; filename=foo.txt");
    Response.Write("some text contents that will be sent to the user");
}

Now simply place this download button somewhere on the page:

<asp:LinkButton 
    ID="BtnDownload" 
    runat="server"
    OnClick="BtnDownload_Click" 
    Text="Download file" 
/>

The FilUpload control you are mentioning in your question is used for the client to upload files to the server, not to download.

Upvotes: 2

Related Questions