文件夹浏览器对话框

本文关键字:对话框 浏览器 文件夹 | 更新日期: 2023-09-27 18:09:16

我已经在C sharp中创建了一个word文档生成器,我希望生成的word文档保存在客户端的特定位置。我正在寻找一个类似的功能,如FolderBrowserDialog在Windows窗体。我用的是ASP。Net和我尝试了许多解决方案,但仍然没有运气。谁都可以帮我。

文件夹浏览器对话框

不!server (web-app)程序没有能力将生成的文档保存在客户端的特定位置。

尝试在后面的代码中使用HttpResponse:

:

// Clear the content of the response
Response.ClearContent();    
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + savedNameWithExtension);
// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);
// End the response
Response.End();

这段代码将提示用户将指定的文件保存到机器上的某个位置。

当您从浏览器下载文件时,浏览器会显示保存文件对话框,这适用于所有浏览器和平台。只需保持默认行为,让用户决定位置和文件名。我想这部分的任何hack实现如果可能的话,很可能在某些浏览器或平台上被破坏,如mac, ipad, android…

您不需要指定要使用的任何控件,一旦您调用方法来下载像

这样的文件

Response.WriteFileResponse.BinaryWrite或任何其他,浏览器为您照顾其他一切,让它像那样;-)