网页的SaveFileDialog等效项 [英] SaveFileDialog equivalent for a webpage
本文介绍了网页的SaveFileDialog等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从高层次看,这似乎并不像火箭科学,但事实证明这是一个挑战.我对c#Windows窗体开发更加熟悉.我现在正在创建一个网页,并且需要将等效于Windows形式的SaveFileDialog功能合并到该网页中.至少,我需要使最终用户能够选择自己的文件路径和名称,并为其保存GridView中的数据.我有什么选择?
At a high-level this does not seem like rocket science, but it is proving to be a challenge. I am more familiar with c# windows form development. I am now creating a webpage and need to incorporate the equivalent of windows form SaveFileDialog functionality into the webpage. At the very least, I need to give the end user the ability to select their own file path and name for which data from a GridView will be saved. What are my options?
推荐答案
我想您想要这样的东西:
I guess you want something like this:
FileStream sourceFile = new FileStream(Server.MapPath(@"FileName"), FileMode.Open);
float FileSize;
FileSize = sourceFile.Length;
byte[] fileContent = new byte[(int)FileSize];
sourceFile.Read(fileContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", fileContent.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.BinaryWrite(fileContent);
Response.Flush();
Response.End();
最好的问候
Espen Harlinn
Best regards
Espen Harlinn
http://forums.asp.net/t/1178720 .aspx/1 [ ^ ]
http://www.pcreview.co.uk/forums/savefiledialog-webforms-t2781396.html [ ^ ]
http://forums.asp.net/t/1178720.aspx/1[^]
http://www.pcreview.co.uk/forums/savefiledialog-webforms-t2781396.html[^]
这篇关于网页的SaveFileDialog等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文