无法使用 asp.net C# 正确读取文件
System.IO.StreamReader sr = new System.IO.StreamReader(Server.MapPath(strheadlinesid1));
string line;
while (sr.Peek() != -1)
{
line = sr.ReadLine();
Response.Write("<tr>"+"<td>"+ Server.HtmlEncode(line) + "</td>"+"</tr>");
}
我正在使用上面的代码来读取文件。但这只是正确读取.txt 文件(不能正确读取.doc、docx 和.rtf)。任何人都可以告诉如何在网络浏览器中阅读 .pdf 文件,例如在新选项卡中在 adobe reader 中打开。谢谢
System.IO.StreamReader sr = new System.IO.StreamReader(Server.MapPath(strheadlinesid1));
string line;
while (sr.Peek() != -1)
{
line = sr.ReadLine();
Response.Write("<tr>"+"<td>"+ Server.HtmlEncode(line) + "</td>"+"</tr>");
}
I'm using the above code to read a file .But this is only reading .txt files properly(Not reading .doc,docx and .rtf properly). And Can anybody tell how to read .pdf files in web browser like opening in a adobe reader in a new tab.Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要下载 PDF 文件,请使用您的 pdf 文件调用此代码:根据用户浏览器的设置,它可能会根据您的需要在新选项卡中打开。
To download a PDF file call this code with your pdf file: Depending on the user's settings for their browser, it may open in a new tab as you want.
您只能通过浏览器的插件在浏览器中阅读 pdf 文件,可从此处下载:
http://kb2.adobe.com/cps/331/331025.html
为了在浏览器中正确查看文件,您应该为其设置 mime 类型:
有关 Mime 类型的更多信息:
http://www.w3schools.com/media/media_mimeref.asp
You can read the pdf file in the browser only by add-in for your browser, downloadable from here:
http://kb2.adobe.com/cps/331/331025.html
For correct view the files in the browser you should set the mime types for it:
More about the Mime types:
http://www.w3schools.com/media/media_mimeref.asp
您的方法读取文件的原始内容。 Txt 文件可以正确显示,因为它们的内容是纯文本,doc/rtf/pdf 和其他格式需要专门的控件才能正确显示。
Your approach reads the raw content of the file. Txt-Files display correctly because their content is plain text, doc/rtf/pdf and other formats will require specialized controls to display them properly.