1

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!

elish
  • 15
  • 5

1 Answers1

1

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.

terbubbs
  • 1,512
  • 2
  • 25
  • 48
  • I get from sql in DataSet like so: ds.Tables[0].Rows[0]["btPassportImage"] what What do I need to fill the variables: 'fileName' and 'bytes'? – elish Jan 12 '16 at 13:53
  • `bytes` should be your byte array and `fileName` can be any string – terbubbs Jan 12 '16 at 13:56
  • Thank! It's good!! 1.Could I know, when I get the file in byte, which type it (jpeg/pdf...)? 2.How could I open the pdf in new tab? – elish Jan 12 '16 at 14:06
  • the easiest way I open PDF in a new tab is through javascript.. `window.open("url");` THEN, in the `Page_Load` for that page, I get the byte[] and execute that code. – terbubbs Jan 12 '16 at 14:10
  • in regards to getting file type from byte[], take a look at this: http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature?lq=1 – terbubbs Jan 12 '16 at 14:10
  • for reference, look at this for storing your byte[] in SQL: http://stackoverflow.com/questions/1064121/how-do-i-insert-a-byte-into-an-sql-server-varbinary-column – terbubbs Jan 12 '16 at 14:11
  • it also looks like you should be able to use that solution in a RadWindow: http://www.telerik.com/forums/rad-window---opening-pdf#DO_oceS7g0KcUSdX4yKq0g – terbubbs Jan 12 '16 at 14:13
  • Could you show me the code that open the byte in new tab? – elish Jan 12 '16 at 14:22
  • all you have to do is assign a javascript function to execute: `window.open("URL to new aspx page");` In the Page_Load of the new aspx page, query out the byte[] you are saving to SQL and then execute the code in my solution. – terbubbs Jan 12 '16 at 14:30
  • It's execlent! Thenk you – elish Jan 13 '16 at 10:03