2011-09-21 107 views
0

我在C sharp中创建了一个Word文档生成器,我希望生成的Word文档保存在客户端的特定位置。我正在寻找类似Windows窗体中的FolderBrowserDialog功能。我使用ASP.Net,我尝试了可能的解决方案,但仍然没有运气。任何人都可以帮助我。ASP.Net中的文件夹浏览器对话框

+0

浏览器本身并没有什么那种效果。你需要一些flash或者一个Java applet来达到这个目的。 – deostroll

回答

0

尝试使用的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(); 

这部分代码会提示用户到指定的文件保存在自己的机器上的某个位置。

希望这是明确的。

+0

我可以使用什么控制来获取保存文档的路径/目录。 – Rob

+0

对不起,请稍后回复, 不要在这里使用任何控件,如果你想保存或取消,提供的代码会弹出如果保存另一个窗口弹出来指定你想保存的文件夹路径 – Boomer

+0

谢谢..现在我知道..我已经得到了我想要的感谢boomer ..(thumbsup) – Rob

1

不! server(网络应用)程序无法将生成的文档保存在客户端的特定位置。

+0

好的,我的意思是这样的,我使用Microsoft Word 12.0 Object Library在C#中创建Word文档后创建那个文档,我希望它保存在客户端机器中。我想用户将浏览他的机器的位置,然后单击生成按钮.. – Rob

+0

@Rob - 您可以通过添加引用该文档的链接或编写代码进行下载,将“生成”文档发送到浏览器。 – adatapost

0

当您从浏览器的浏览器中下载文件以显示保存文件对话框,并且这适用于所有浏览器和所有平台。只需保持默认行为并让用户决定位置和文件名称即可。我猜如果可能的话,任何hacky实现该部分,它很可能会在一些浏览器或平台,如mac,ipad,android中断...

你不需要指定任何控制使用,一次你调用的方法来下载文件一样

Response.WriteFileResponse.BinaryWrite或任何其他浏览器需要照顾的一切别人为你,让它成为像;-)