More in this section

Forums / Developing with Sitefinity / IContent.Content byte[] to Object

IContent.Content byte[] to Object

3 posts, 0 answered
  1. Garry
    Garry avatar
    52 posts
    04 Nov 2010
    24 Jul 2009
    Link to this post
    First off let me say I am still amazed by the efficency and speed at which Telerik responds to our posts out here on the Forums. It is the number one reason why I switched from Infragistics to Telerik and have never looked back. With that being said I am sorry to bother you with yet another question.

    OK now that I got you all buttered up here is my issue. Long story short I have a custom library that contains Crystal Report files (.rpt).
    <add name="Report" title="Report Library" defaultExtenstions=".rpt" metaKeys="Author, Description, Extension, Name, Size, Category">  

    I am now needing to get those files back out of the library and load them into the Crystal Report Viewer. The code I have been playing with looks like so.
    LibraryManager manager = new LibraryManager();  
                Telerik.Cms.Engine.IContent report = manager.GetContent(new Guid("75519f20-ef53-46a0-ad96-b9ef45149061"));  
                if (report != null)  
                    ReportDocument doc = new ReportDocument();  
                    MemoryStream memStream = new MemoryStream();  
                    BinaryFormatter binForm = new BinaryFormatter();  
                    memStream.Write((Byte[])report.Content, 0, ((byte[])report.Content).Length);  
                    memStream.Seek(0, SeekOrigin.Begin);  
                    Object obj = (Object)binForm.Deserialize(memStream);  
                    reportViewer.ReportSource = (ReportDocument)obj;  

    The issue is that the ReportDocument class apparently is not Deserializable and I get the usual error of:
    Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization. 

    My question is how can I go about converting the IContent.Content Byte[] back into a Crystal ReportDocument object without writing the memorystream or the Byte[] back out to disk?

    Also just on a side question which is very low priority, is there away to define an icon or image for my Crystal Reports Library like the builtin libraries, Document, Image, and Custom have?

    Thanks as always!

  2. Dido
    Dido avatar
    149 posts
    24 Sep 2012
    29 Jul 2009
    Link to this post
    Hello Garry Clark,

    I have only just browsed their documentation, and it seems very vague, to say the least. Nevertheless, here is what you can try to do (since their objects are obviously not serializable and there is no way to load from memory):
    I could only come up with writing temporary files from the byte[] array that you get with File.WriteAllBytes and Path.GetRandomFileName.  Of course, resources will have to be cleaned up (most probably with using statement).

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. Garry
    Garry avatar
    52 posts
    04 Nov 2010
    29 Jul 2009
    Link to this post
    Thank you very much for yoru response and yeah I was afraid you were going to say that. I was hoping you brillant people at Telerik knew of another method to convert that Byte[] to an Object. Oh well.

    Yeah I was really surprised that BusinessObjects ReportDocument class does not have a load method that takes a Stream of some sort. You pretty much have to always load from a physical file.

    Anyhow thank you again. Your help is much appreciated!

Register for webinar
3 posts, 0 answered