locked
Embed a video file into a document using open xml RRS feed

  • Question

  • hi ,

    i would like to know how can we embed a video file programatically into a word document. have seen there is an option to embed documents/html/rtf using altchunk but not video file.

    appreciate your help if you point to any sample or so.

    thanks,

    Kumar

    Sunday, November 29, 2020 5:40 AM

All replies

  • my code looks like the below

    MainDocumentPart mainPart = myDoc.MainDocumentPart;
    ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png);
    //imagePart.FeedData(File.Open(@"filepathimage", FileMode.Open));
    EmbeddedPackagePart embeddedObjectPart = mainPart.AddEmbeddedPackagePart(@"application/vnd.openxmlformats-officedocument.oleObject");
    embeddedObjectPart.FeedData(File.Open(@"fielpath", FileMode.Open));
    Paragraph p = Test.CreateEmbeddedObjectParagraph(mainPart.GetIdOfPart(imagePart), mainPart.GetIdOfPart(embeddedObjectPart));
    myDoc.MainDocumentPart.Document.Body.AppendChild(p);

    mainPart.Document.Save();

    Code in Test Class

    public static Paragraph CreateEmbeddedObjectParagraph(string imageId, string embedId)
    {
    Paragraph p = new Paragraph(new Run(new EmbeddedObject(new Shapetype(new Stroke() { JoinStyle = StrokeJoinStyleValues.Miter }, new Formulas(new Formula() { Equation = "if lineDrawn pixelLineWidth 0" }, new Formula() { Equation = "sum @0 1 0" }, new Formula() { Equation = "sum 0 0 @1" }, new Formula() { Equation = "prod @2 1 2" }, new Formula() { Equation = "prod @3 21600 pixelWidth" }, new Formula() { Equation = "prod @3 21600 pixelHeight" }, new Formula() { Equation = "sum @0 0 1" }, new Formula() { Equation = "prod @6 1 2" }, new Formula() { Equation = "prod @7 21600 pixelWidth" }, new Formula() { Equation = "sum @8 21600 0" }, new Formula() { Equation = "prod @7 21600 pixelHeight" }, new Formula() { Equation = "sum @10 21600 0" }), new Path() { AllowGradientShape = true, ConnectionPointType =ConnectValues.Rectangle, AllowExtrusion = false }, new DocumentFormat.OpenXml.Vml.Office.Lock() { Extension = ExtensionHandlingBehaviorValues.Edit, AspectRatio = true }) { Id = "_x0000_t75", CoordinateSize = "21600,21600", Filled = false, Stroked = false, OptionalNumber = 75, PreferRelative = true, EdgePath = "m@4@5l@4@11@9@11@9@5xe" }, new Shape(new ImageData() { Title = "", RelationshipId = imageId }) { Id = "_x0000_i1025", Style = "width:500pt;height:400pt", Type = "#_x0000_t75" }, new OleObject() { Type = OleValues.Embed, ProgId = "WMP11.AssocFile.WAV", ShapeId = "_x0000_i1025", DrawAspect = OleDrawAspectValues.Content, ObjectId = "_1307530183", Id = embedId }) { DxaOriginal = 10957U.ToString(), DyaOriginal = 8455U.ToString() })); return p;

    }

    Not sure where i am going wrong. document is opening. video is getting embeded in embeddings folder but unable to open it on click. Any help

    Monday, November 30, 2020 2:41 PM