如何让用户在asp.net中选择下载文件的位置??准确地说,asp中等效的打开文件对话框(不是文件上载)

如何让用户在asp.net中选择下载文件的位置??准确地说,asp中等效的打开文件对话框(不是文件上载),asp.net,openfiledialog,Asp.net,Openfiledialog,我正在我的项目中下载一个pdf文件。我想让用户决定在哪里下载文件。快速帮助是有帮助的 谢谢试试这个: 它将在浏览器中显示一个对话框,用户将选择保存文件的位置 protected void DownloadFile_Click(object sender, EventArgs e) { String Filepath; System.IO.FileInfo file = new System.IO.FileInfo(Filepath); // full file path on dis

我正在我的项目中下载一个pdf文件。我想让用户决定在哪里下载文件。快速帮助是有帮助的

谢谢

试试这个:

它将在浏览器中显示一个对话框,用户将选择保存文件的位置

protected void DownloadFile_Click(object sender, EventArgs e)
 {
  String Filepath;
  System.IO.FileInfo file =  new System.IO.FileInfo(Filepath); // full file path on disk
  Response.ClearContent(); // Clear previous content
  Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
  Response.AddHeader("Content-Length", file.Length.ToString());
  Response.ContentType = "application/pdf";
  Response.TransmitFile(file.FullName);
  Response.End();
 }

您尚未指定应用程序如何提供此PDF文件,但假设您有一些Web表单正在将其流式传输到响应,则应将内容处置标头设置为附件,以强制浏览器中的“另存为”对话框

例如:

protected void Download(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment; filename=example.pdf");
    Response.WriteFile(@"c:\work\example.pdf");
}

你好,达林,我可以下载它的默认文件夹的浏览器。但是我想让用户决定下载的位置,这是不可能的。你不能从服务器上控制它。那么最好的方法是什么??至少我不想硬编码路径。用户下载文件的文件夹无法从服务器控制。嗨,Dyrandz,我可以知道这个下载文件是什么吗?单击??事件关联到的用户控件是什么?抱歉。这没用。它不显示任何对话框。