Avatar of DarklingG
DarklingG
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Tyring to Serialize/Deserialize Office Class Objects

I'm currently working an Reporting System to produce large amounts of Powerpoint Presentations from set data sources. This is all fine.

 But, my users don't always want to use just the standard set of Powerpoint Slides, they want to have custom ones depending on the service they provide.

 What I need to do is easily serialize individual Slides into Binary or SOAP (currently using Binary) and store them in a database so I can retrieve them.

 The below is working fine for images and custom classes, etc., but won't work with the Office Objects.

 Can someone help as to why? And hopefully provide an answer?




public class GeneralObjectSerialization<T>
    {
 
        BinaryFormatter newBin;
        MemoryStream newStream;
 
        public byte[] SerializeObjectAndReturnByteArray(T newObject)
        {
            byte[] newByteArray;
 
            newBin = new BinaryFormatter();
            newStream = new MemoryStream();
 
            newBin.Serialize(newStream, newObject);
            newByteArray = newStream.GetBuffer();
            newStream.Close();
            
            return newByteArray;
            
        }
 
        public T Deserialize(byte[] arrayStream)
        {
            T newObject;
 
            newBin = new BinaryFormatter();
            newStream = new MemoryStream();
            
 
            newStream.Write(arrayStream,0,arrayStream.Length);
            newStream.Seek(0, 0);
            newObject = (T)newBin.Deserialize(newStream);
 
            return newObject;
 
        }
        
    }

Open in new window

C#Microsoft Office

Avatar of undefined
Last Comment
DarklingG

8/22/2022 - Mon
REA_ANDREW

When you try do you get a serialization exception explaining that the objects i.e. the slide objects are not serializable?

Andrew
DarklingG

ASKER
Yes.

 It just doesn't want to serialize the SlideClass class.
ASKER CERTIFIED SOLUTION
REA_ANDREW

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
DarklingG

ASKER

 I thought that would be the route I'd need to take.

 Shame, I thought I was missing something small that solve all the worries for me.


 Cheers!
Your help has saved me hundreds of hours of internet surfing.
fblack61
REA_ANDREW

Can you post the fully qualified name of the Slide Object pls.
DarklingG

ASKER
Not sure what you're after here, but I have:

  GeneralObjectSerialization newSer = new GeneralObjectSerialization();
  SlideClass newSlide;
  newSlide = newPres.Slides[1];    // 1 for example

  byte[] newData = SerializeObjectAndReturnByteArray(newSlide);
 

 I haven't had time to create my personal abstract slide class yet.
DarklingG

ASKER

FYI. I have elected to split out the Slides I need into individual presentations and then store the entire file via a FileStream serialization.

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.