开发者

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 oth开发者_C百科er way to do this? please help . Thanks.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜