以下是我上传和打开PDF
文档
<asp:LinkButton ID="linkButton" runat="server"
onclick="linkButton_Click">Show PDF</asp:LinkButton>
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"
MultipleFileSelection="Disabled"
MaxFileInputsCount="1" Width="230px">
</telerik:RadAsyncUpload>
protected void linkButton_Click(object sender, EventArgs e)
{
if (RadAsyncUpload1.UploadedFiles.Count != 0)
{
byte[] _myfile = null;
UploadedFile _file = RadAsyncUpload1.UploadedFiles[0];
_myfile = new byte[_file.InputStream.Length];
_file.InputStream.Read(_myfile , 0, (int)_file.InputStream.Length);
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Length", _fileItenary.Length.ToString());
Response.AddHeader("Content-Disposition", "inline; filename=sample.pdf");
Response.BinaryWrite(_fileItenary);
Response.Flush();
Response.End();
}
}
此代码正常运行,可以在浏览器中显示我上传的pdf
但是,pdf文件显示在同一页面(相同的标签)
点击我的Show PDF
链接后,我想在新页面(新标签页)中查看我的pdf
请帮助我,谢谢:)
答案 0 :(得分:3)
您可以在客户端使用类似的内容进行操作
OnClientClick="aspnetForm.target ='_blank';"/
或
<script type="text/javascript">
function OpenWindow()
{
window.open('nameofyourpage.aspx','_blank','height=450,width=500,scrollbars=0,location=1,toolbar=0');
}
</script>
OnClientClick="OpenWindow()`enter code here`"/