elish
elish

Reputation: 15

How to view pdf file

I save file with 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" />

in code behind I do:

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;
        }
    }

and save in sql in column data type: varbinary(MAX).

for view the file I use on:

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

but my problem is, when I view file type pdf, it's dont Work. I see the picture like so:

enter image description here

Hope your help Tanks!

Upvotes: 1

Views: 644

Answers (1)

terbubbs
terbubbs

Reputation: 1512

PDF is not a supported DataValue of RadBinaryImage

You can also read further down that thread for another solution on how to display the PDF file.

This is how I've done it:

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();

Similar to what is in the telerik thread, I open a new window and do a binary write of the byte array.

Upvotes: 1

Related Questions