views:

11

answers:

1

Hi

I have used this example when exporting data to powerpoint:

I have modified the GenerateSlidesFromDB() method:

public void GenerateSlidesFromDB()
    {
        string slideName = @"C:\Users\x\Desktop\output.pptx";
        File.Copy(@"C:\Users\x\Desktop\Test.pptx", slideName, true);

        using (PresentationDocument presentationDocument = PresentationDocument.Open(slideName, true))
        {
            PresentationPart presentationPart = presentationDocument.PresentationPart;
            SlidePart slideTemplate = (SlidePart)presentationPart.GetPartById("rId2");
            string firstName = "Test User";
            SlidePart newSlide = CloneSlidePart(presentationPart, slideTemplate);
            InsertContent(newSlide, firstName);
            newSlide.Slide.Save();
            DeleteTemplateSlide(presentationPart, slideTemplate);
            presentationPart.Presentation.Save();
        }
    }

As you can see I overwrite the placeholder with "Test User", and it works like a charm. I need to add an image (as a placeholder) to this pptx-file.

When I do that (and run the code again) I get a corrupted pptx-file. Error message: Powerpoint removed unreadable content in output.pptx. You should review this presentation to determine whether any content was unexpectedly changed or removed.

Edit: If I try the original code (which is slightly modified since I dont have Adventureworks), I get some other kind of error message:

This file may have become corrupt or damaged for the following reasons: Third-party XML editors sometimes create files that are not compatible with Microsoft Office XML specifications. The file has been purposely corrupted with the intent to harm your computer or your data. Be cautious when opening a file from an unknown source. PowerPoint can attempt to recover data from the file, but some presentation data, such as shapes, text,and formatting, may be lost. Do one of the following: If you want to recover data from the file, click Yes. If you do not want to recoverdata from the file, click No.

Thanks...

A: 

Ok, sorry for this useless post. My bad.

Solution:

 string imgId = "rIdImg" + i;
                ImagePart imagePart = newSlide.AddImagePart(ImagePartType.Jpeg, imgId);
                MemoryStream stream3 = new MemoryStream();
                using (FileStream file = File.Open(@"C:\Users\x\Desktop\Test.jpg", FileMode.Open))
                {
                    byte[] buffer = new byte[file.Length];
                    file.Read(buffer, 0, (int)file.Length);
                    stream3.Write(buffer, 0, buffer.Length);
                    imagePart.FeedData(new MemoryStream(buffer));
                }
                SwapPhoto(newSlide, imgId);
Mr. Powerpoint