c#.net网站-如何让用户选择文件夹? [英] c#.net website - How to let user choose a folder?

查看:52
本文介绍了c#.net网站-如何让用户选择文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想单击按钮打开一个对话框.用户将选择一个目标文件夹,然后使用对话框中的路径在选定的文件夹中创建一个文本文件.

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.

我已经使用过asp.net的FileUpload来上传文件,但是我不知道如何使用它来选择文件夹.还是有其他方法可以做到这一点?请帮忙 .谢谢.

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.

推荐答案

您可以在用户计算机上写入文件夹的唯一方法是让用户单击按钮,然后服务器将发送该文件,然后将提示用户输入要保存的位置:

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" 
/>

您在问题中提到的 FilUpload 控件用于客户端将文件上传到服务器而不是下载.

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

这篇关于c#.net网站-如何让用户选择文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆