如何查看pdf文件

How to view pdf file

我使用 telerik RadAsyncUpload (asp) 保存文件:

<telerik:RadAsyncUpload runat="server" Localization-Select="select file" Localization-Remove="delete" 
                    Width="10px" ID="RadAsyncUpload1" MultipleFileSelection="Automatic" AllowedFileExtensions="jpg,jpeg,png,gif,pdf" 
                    ControlObjectsVisibility="None" EnableFileInputSkinning="true" />

在我后面的代码中:

byte[] bytes = null;

    if (RadAsyncUpload1 != null)
    {
        foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
        {
            bytes = new byte[file.ContentLength];
            file.InputStream.Read(bytes, 0, file.ContentLength);
            WinPic.VisibleOnPageLoad = true;
            BinaryImage.DataValue = bytes;
        }
    }

并保存在sql列数据类型:varbinary(MAX).

查看我使用的文件:

<telerik:RadBinaryImage runat="server" ID="BinaryImage" Width="600px" Height="600px" 
                ResizeMode="Fit" AutoAdjustImageControlSize="true" DecoratedControls="All" />

但我的问题是,当我查看文件类型 pdf 时,它不起作用。 我看图是这样的:

enter image description here

希望得到您的帮助 坦克!

PDF is not a supported DataValue of RadBinaryImage

您还可以进一步阅读该主题,了解有关如何显示 PDF 文件的另一种解决方案。

我是这样做的:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + fileName + ".pdf");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();

与 telerik 线程中的类似,我打开一个新的 window 并对字节数组进行二进制写入。