3

我将 PDF 文件保存在 Web 应用程序外部服务器的文件夹中(出于安全原因),我需要使用 google 文档预览文件。

<iframe src="http://docs.google.com/gview?url=????&embedded=true" 
        style="width:718px; height:700px;" frameborder="0"></iframe>

到现在为止,我通过以文件路径作为参数的形式重定向以使它们可供下载:

string path = Request.QueryString["src"];
int index = Request.QueryString["src"].ToString().LastIndexOf("\\");
string filename = Request.QueryString["src"].ToString().Substring(index + 1);
FileStream fileStream = new FileStream(path, FileMode.Open);
int fileSize = (int)fileStream.Length;
byte[] Buffer = new byte[fileSize];
fileStream.Read(Buffer, 0, fileSize);
fileStream.Close();
Response.ContentType = ContType(path);
Response.AddHeader("content-disposition", "attachment;filename=\"" + filename);
Response.BinaryWrite(Buffer);
Response.End();

我尝试将 url 添加file.aspx?src=C:\...为 google doc iframe 的 url 的参数,比如

http://docs.google.com/gview?url=file.aspx?src=C:\...

但它不起作用。

有没有其他方法可以将 URL 分配给流?

4

1 回答 1

0

你可以尝试这样的事情:

<iframe src="http://docs.google.com/gview?url='file.aspx?src='C:\storage\test.pdf''&embedded=true" 
        style="width:718px; height:700px;" frameborder="0"></iframe>

根据需要将 ' 与 " 交替使用。

作为旁注,我建议您不要将完整的文件路径从服务器发送到客户端的浏览器。这听起来像是将 50 英寸电视、蓝光播放器、电脑和其他贵重物品放在您家中的位置草稿,供任何潜在的小偷考虑。

作为替代方案,您可以使用带有 ID 的数据库或 XML 文件来识别每个文件,并从那里读取文件路径。

于 2012-12-21T18:33:50.063 回答