From c99ff5a34427fa938f70ceadd407767ec061c11f Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Wed, 26 Mar 2025 14:19:50 +0000 Subject: [PATCH 01/14] added c#/vb code --- ...dd-a-video-to-a-slide-in-a-presentation.md | 167 ++++++++++++++++++ samples/presentation/add_video/cs/Program.cs | 143 +++++++++++++++ .../add_video/cs/add_video_cs.csproj | 10 ++ samples/presentation/add_video/vb/Program.vb | 162 +++++++++++++++++ .../add_video/vb/add_video_vb.vbproj | 9 + .../cs/insert_a_new_slideto_cs.csproj | 6 +- samples/samples.sln | 14 ++ 7 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md create mode 100644 samples/presentation/add_video/cs/Program.cs create mode 100644 samples/presentation/add_video/cs/add_video_cs.csproj create mode 100644 samples/presentation/add_video/vb/Program.vb create mode 100644 samples/presentation/add_video/vb/add_video_vb.vbproj diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md new file mode 100644 index 00000000..c705c3e1 --- /dev/null +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -0,0 +1,167 @@ +--- + +api_name: +- Microsoft.Office.DocumentFormat.OpenXML.Packaging +api_type: +- schema +ms.assetid: 403abe97-7ab2-40ba-92c0-d6312a6d10c8 +title: 'How to: Add a video to a slide in a presentation' +ms.suite: office + +ms.author: o365devx +author: o365devx +ms.topic: conceptual +ms.date: 02/25/2025 +ms.localizationpriority: medium +--- + +# Add a video to a slide in a presentation + +This topic shows how to use the classes in the Open XML SDK for +Office to add a video to the first slide in a presentation +programmatically. + +## Getting a Presentation Object + +In the Open XML SDK, the `PresentationDocument` class represents a +presentation document package. To work with a presentation document, +first create an instance of the `PresentationDocument` class, and then work with +that instance. To create the class instance from the document call the +`Open` method that uses a file path, and a +Boolean value as the second parameter to specify whether a document is +editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following +`using` statement. In this code, the file +parameter is a string that represents the path for the file from which +you want to open the document. + +### [C#](#tab/cs-1) +[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet1)] + +### [Visual Basic](#tab/vb-1) +[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet1)] +*** + + +[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`. + + +## The Structure of the Video From File + +The basic document structure of a PresentationML document consists of a +number of parts, among which is the Shape Tree (`<spTree/>`) element. + +The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification +introduces the overall form of a `PresentationML` package. + +> This element specifies the presence of a video file. It is defined +> within the non-visual properties of an object. The video is attached to an object, representing it +> shall be attached to an object as this is how it is represented within +> the document. The actual playing of the video however is done within +> the timing node list that is specified under the timing element. +> +> [*Example*: Consider the following ``Picture`` object that has a video attached to it. + +```xml + <p:sld> + <p:cSld> + <p:spTree> + <p:nvGrpSpPr> + .. + </p:nvGrpSpPr> + <p:grpSpPr> + .. + </p:grpSpPr> + <p:sp> + .. + </p:sp> + </p:spTree> + </p:cSld> + .. + </p:sld> +``` + +> In the above example the shape tree specifies all the shape properties +> for this slide. *end example*] +> +> © [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)] + +The following table lists the child elements of the Shape Tree along +with the description of each. + +| Element | Description | +|---|---| +| cxnSp | Connection Shape | +| extLst | Extension List with Modification Flag | +| graphicFrame | Graphic Frame | +| grpSp | Group Shape | +| grpSpPr | Group Shape Properties | +| nvGrpSpPr | Non-Visual Properties for a Group Shape | +| pic | Picture | +| sp | Shape | + +The following XML Schema fragment defines the contents of this element. + +```xml + <complexType name="CT_GroupShape"> + <sequence> + <element name="nvGrpSpPr" type="CT_GroupShapeNonVisual" minOccurs="1" maxOccurs="1"/> + <element name="grpSpPr" type="a:CT_GroupShapeProperties" minOccurs="1" maxOccurs="1"/> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="sp" type="CT_Shape"/> + <element name="grpSp" type="CT_GroupShape"/> + <element name="graphicFrame" type="CT_GraphicalObjectFrame"/> + <element name="cxnSp" type="CT_Connector"/> + <element name="pic" type="CT_Picture"/> + </choice> + <element name="extLst" type="CT_ExtensionListModify" minOccurs="0" maxOccurs="1"/> + </sequence> + </complexType> +``` + +## How the Sample Code Works + +After opening the presentation file for read/write access in the `using` statement, the code gets the presentation +part from the presentation document. Then it gets the relationship ID of +the first slide, and gets the slide part from the relationship ID. + +> [!NOTE] +> The test file must have a shape on the first slide. + +### [C#](#tab/cs-2) +[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet2)] + +### [Visual Basic](#tab/vb-2) +[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet2)] +*** + + +The code then gets the shape tree that contains the shape whose fill +color is to be changed, and gets the first shape in the shape tree. It +then gets the shape properties of the shape and the solid fill reference of the shape properties, +and assigns a new fill color to the shape. There is no need to explicitly +save the file when inside of a using. + +### [C#](#tab/cs-3) +[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet3)] + +### [Visual Basic](#tab/vb-3) +[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet3)] +*** + + +## Sample Code + +Following is the complete sample code that you can use to change the +fill color of a shape in a presentation. +### [C#](#tab/cs) +[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet0)] + +### [Visual Basic](#tab/vb) +[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet0)] +*** + +## See also + + + +- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs new file mode 100644 index 00000000..29dd7c71 --- /dev/null +++ b/samples/presentation/add_video/cs/Program.cs @@ -0,0 +1,143 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Presentation; +using A = DocumentFormat.OpenXml.Drawing; +using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint; +using ShapeTree = DocumentFormat.OpenXml.Presentation.ShapeTree; +using ShapeProperties = DocumentFormat.OpenXml.Presentation.ShapeProperties; +using NonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties; +using NonVisualPictureProperties = DocumentFormat.OpenXml.Presentation.NonVisualPictureProperties; +using NonVisualPictureDrawingProperties = DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties; +using Picture = DocumentFormat.OpenXml.Presentation.Picture; +using BlipFill = DocumentFormat.OpenXml.Presentation.BlipFill; +using DocumentFormat.OpenXml.Packaging; +using ApplicationNonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties; + + +AddVideo(args[0], args[1], args[2]); + +static void AddVideo(string filePath, string videoFilePath, string coverPicPath) +{ + + string imgEmbedId = "rId4", embedId = "rId3", mediaEmbedId = "rId2"; + UInt32Value shapeId = 5; + // <Snippet1> + using (PresentationDocument presentationDocument = PresentationDocument.Open(filePath, true)) + // </Snippet1> + { + + if (presentationDocument.PresentationPart == null || presentationDocument.PresentationPart.Presentation.SlideIdList == null) + { + throw new NullReferenceException("Presenation Part is empty or there are no slides in it"); + } + + //Get presentation part + PresentationPart presentationPart = presentationDocument.PresentationPart; + + //Get slides ids. + OpenXmlElementList slidesIds = presentationPart.Presentation.SlideIdList.ChildElements; + + + //Get relationsipId of the last slide + string? videoSldRelationshipId = ((SlideId) slidesIds[0]).RelationshipId; + + if (videoSldRelationshipId == null) + { + throw new NullReferenceException("Slide id not found"); + } + + //Get slide part by relationshipID + SlidePart? slidePart = (SlidePart) presentationPart.GetPartById(videoSldRelationshipId); + + // Create video Media Data Part (content type, extension) + MediaDataPart mediaDataPart = presentationDocument.CreateMediaDataPart("video/mp4", ".mp4"); + + //Get the video file and feed the stream + using (Stream mediaDataPartStream = File.OpenRead(videoFilePath)) + { + mediaDataPart.FeedData(mediaDataPartStream); + } + //Adds a VideoReferenceRelationship to the MainDocumentPart + slidePart.AddVideoReferenceRelationship(mediaDataPart, embedId); + + //Adds a MediaReferenceRelationship to the SlideLayoutPart + slidePart.AddMediaReferenceRelationship(mediaDataPart, mediaEmbedId); + + NonVisualDrawingProperties nonVisualDrawingProperties = new NonVisualDrawingProperties() { Id = shapeId, Name = "video" }; + A.VideoFromFile videoFromFile = new A.VideoFromFile() { Link = embedId }; + + ApplicationNonVisualDrawingProperties appNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties(); + appNonVisualDrawingProperties.Append(videoFromFile); + + //adds sample image to the slide with id to be used as reference in blip + ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, imgEmbedId); + using (Stream data = File.OpenRead(coverPicPath)) + { + imagePart.FeedData(data); + } + + if (slidePart!.Slide!.CommonSlideData!.ShapeTree == null) + { + throw new NullReferenceException("Presenation shape tree is empty"); + } + + //Getting existing shape tree object from PowerPoint + ShapeTree shapeTree = slidePart.Slide.CommonSlideData.ShapeTree; + + // specifies the existence of a picture within a presentation. + // It can have non-visual properties, a picture fill as well as shape properties attached to it. + Picture picture = new Picture(); + NonVisualPictureProperties nonVisualPictureProperties = new NonVisualPictureProperties(); + + A.HyperlinkOnClick hyperlinkOnClick = new A.HyperlinkOnClick() { Id = "", Action = "ppaction://media" }; + nonVisualDrawingProperties.Append(hyperlinkOnClick); + + NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties = new NonVisualPictureDrawingProperties(); + A.PictureLocks pictureLocks = new A.PictureLocks() { NoChangeAspect = true }; + nonVisualPictureDrawingProperties.Append(pictureLocks); + + ApplicationNonVisualDrawingPropertiesExtensionList appNonVisualDrawingPropertiesExtensionList = new ApplicationNonVisualDrawingPropertiesExtensionList(); + ApplicationNonVisualDrawingPropertiesExtension appNonVisualDrawingPropertiesExtension = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" }; + + P14.Media media = new() { Embed = mediaEmbedId }; + media.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); + + appNonVisualDrawingPropertiesExtension.Append(media); + appNonVisualDrawingPropertiesExtensionList.Append(appNonVisualDrawingPropertiesExtension); + appNonVisualDrawingProperties.Append(appNonVisualDrawingPropertiesExtensionList); + + nonVisualPictureProperties.Append(nonVisualDrawingProperties); + nonVisualPictureProperties.Append(nonVisualPictureDrawingProperties); + nonVisualPictureProperties.Append(appNonVisualDrawingProperties); + + //Prepare shape properties to display picture + BlipFill blipFill = new BlipFill(); + A.Blip blip = new A.Blip() { Embed = imgEmbedId }; + + A.Stretch stretch = new A.Stretch(); + A.FillRectangle fillRectangle = new A.FillRectangle(); + A.Transform2D transform2D = new A.Transform2D(); + A.Offset offset = new A.Offset() { X = 1524000L, Y = 857250L }; + A.Extents extents = new A.Extents() { Cx = 9144000L, Cy = 5143500L }; + A.PresetGeometry presetGeometry = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle }; + A.AdjustValueList adjValueList = new A.AdjustValueList(); + + stretch.Append(fillRectangle); + blipFill.Append(blip); + blipFill.Append(stretch); + transform2D.Append(offset); + transform2D.Append(extents); + presetGeometry.Append(adjValueList); + + ShapeProperties shapeProperties = new ShapeProperties(); + shapeProperties.Append(transform2D); + shapeProperties.Append(presetGeometry); + + //adds all elements to the slide's shape tree + picture.Append(nonVisualPictureProperties); + picture.Append(blipFill); + picture.Append(shapeProperties); + + shapeTree.Append(picture); + + } +} \ No newline at end of file diff --git a/samples/presentation/add_video/cs/add_video_cs.csproj b/samples/presentation/add_video/cs/add_video_cs.csproj new file mode 100644 index 00000000..fd4bd08d --- /dev/null +++ b/samples/presentation/add_video/cs/add_video_cs.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net9.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/samples/presentation/add_video/vb/Program.vb b/samples/presentation/add_video/vb/Program.vb new file mode 100644 index 00000000..5d2574db --- /dev/null +++ b/samples/presentation/add_video/vb/Program.vb @@ -0,0 +1,162 @@ +Imports DocumentFormat.OpenXml +Imports DocumentFormat.OpenXml.Presentation +Imports A = DocumentFormat.OpenXml.Drawing +Imports P14 = DocumentFormat.OpenXml.Office2010.PowerPoint +Imports ShapeTree = DocumentFormat.OpenXml.Presentation.ShapeTree +Imports ShapeProperties = DocumentFormat.OpenXml.Presentation.ShapeProperties +Imports NonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties +Imports NonVisualPictureProperties = DocumentFormat.OpenXml.Presentation.NonVisualPictureProperties +Imports NonVisualPictureDrawingProperties = DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties +Imports Picture = DocumentFormat.OpenXml.Presentation.Picture +Imports BlipFill = DocumentFormat.OpenXml.Presentation.BlipFill +Imports DocumentFormat.OpenXml.Packaging +Imports ApplicationNonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties +Imports System.IO + +Module Program + Sub Main(args As String()) + AddVideo(args(0), args(1), args(2)) + End Sub + + Sub AddVideo(filePath As String, videoFilePath As String, coverPicPath As String) + Dim imgEmbedId As String = "rId4" + Dim embedId As String = "rId3" + Dim mediaEmbedId As String = "rId2" + Dim shapeId As UInt32Value = 5 + ' <Snippet1> + Using presentationDocument As PresentationDocument = PresentationDocument.Open(filePath, True) + ' </Snippet1> + If presentationDocument.PresentationPart Is Nothing OrElse presentationDocument.PresentationPart.Presentation.SlideIdList Is Nothing Then + Throw New NullReferenceException("Presentation Part is empty or there are no slides in it") + End If + + ' Get presentation part + Dim presentationPart As PresentationPart = presentationDocument.PresentationPart + + ' Get slides ids + Dim slidesIds As OpenXmlElementList = presentationPart.Presentation.SlideIdList.ChildElements + + ' Get relationshipId of the last slide + Dim videoSldRelationshipId As String = CType(slidesIds(0), SlideId).RelationshipId + + If videoSldRelationshipId Is Nothing Then + Throw New NullReferenceException("Slide id not found") + End If + + ' Get slide part by relationshipID + Dim slidePart As SlidePart = CType(presentationPart.GetPartById(videoSldRelationshipId), SlidePart) + + ' Create video Media Data Part (content type, extension) + Dim mediaDataPart As MediaDataPart = presentationDocument.CreateMediaDataPart("video/mp4", ".mp4") + + ' Get the video file and feed the stream + Using mediaDataPartStream As Stream = File.OpenRead(videoFilePath) + mediaDataPart.FeedData(mediaDataPartStream) + End Using + + ' Adds a VideoReferenceRelationship to the MainDocumentPart + slidePart.AddVideoReferenceRelationship(mediaDataPart, embedId) + + ' Adds a MediaReferenceRelationship to the SlideLayoutPart + slidePart.AddMediaReferenceRelationship(mediaDataPart, mediaEmbedId) + + Dim nonVisualDrawingProperties As New NonVisualDrawingProperties() With { + .Id = shapeId, + .Name = "video" + } + Dim videoFromFile As New A.VideoFromFile() With { + .Link = embedId + } + + Dim appNonVisualDrawingProperties As New ApplicationNonVisualDrawingProperties() + appNonVisualDrawingProperties.Append(videoFromFile) + + ' Adds sample image to the slide with id to be used as reference in blip + Dim imagePart As ImagePart = slidePart.AddImagePart(ImagePartType.Png, imgEmbedId) + Using data As Stream = File.OpenRead(coverPicPath) + imagePart.FeedData(data) + End Using + + If slidePart.Slide.CommonSlideData.ShapeTree Is Nothing Then + Throw New NullReferenceException("Presentation shape tree is empty") + End If + + ' Getting existing shape tree object from PowerPoint + Dim shapeTree As ShapeTree = slidePart.Slide.CommonSlideData.ShapeTree + + ' Specifies the existence of a picture within a presentation + Dim picture As New Picture() + Dim nonVisualPictureProperties As New NonVisualPictureProperties() + + Dim hyperlinkOnClick As New A.HyperlinkOnClick() With { + .Id = "", + .Action = "ppaction://media" + } + nonVisualDrawingProperties.Append(hyperlinkOnClick) + + Dim nonVisualPictureDrawingProperties As New NonVisualPictureDrawingProperties() + Dim pictureLocks As New A.PictureLocks() With { + .NoChangeAspect = True + } + nonVisualPictureDrawingProperties.Append(pictureLocks) + + Dim appNonVisualDrawingPropertiesExtensionList As New ApplicationNonVisualDrawingPropertiesExtensionList() + Dim appNonVisualDrawingPropertiesExtension As New ApplicationNonVisualDrawingPropertiesExtension() With { + .Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" + } + + Dim media As New P14.Media() With { + .Embed = mediaEmbedId + } + media.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main") + + appNonVisualDrawingPropertiesExtension.Append(media) + appNonVisualDrawingPropertiesExtensionList.Append(appNonVisualDrawingPropertiesExtension) + appNonVisualDrawingProperties.Append(appNonVisualDrawingPropertiesExtensionList) + + nonVisualPictureProperties.Append(nonVisualDrawingProperties) + nonVisualPictureProperties.Append(nonVisualPictureDrawingProperties) + nonVisualPictureProperties.Append(appNonVisualDrawingProperties) + + ' Prepare shape properties to display picture + Dim blipFill As New BlipFill() + Dim blip As New A.Blip() With { + .Embed = imgEmbedId + } + + Dim stretch As New A.Stretch() + Dim fillRectangle As New A.FillRectangle() + Dim transform2D As New A.Transform2D() + Dim offset As New A.Offset() With { + .X = 1524000L, + .Y = 857250L + } + Dim extents As New A.Extents() With { + .Cx = 9144000L, + .Cy = 5143500L + } + Dim presetGeometry As New A.PresetGeometry() With { + .Preset = A.ShapeTypeValues.Rectangle + } + Dim adjValueList As New A.AdjustValueList() + + stretch.Append(fillRectangle) + blipFill.Append(blip) + blipFill.Append(stretch) + transform2D.Append(offset) + transform2D.Append(extents) + presetGeometry.Append(adjValueList) + + Dim shapeProperties As New ShapeProperties() + shapeProperties.Append(transform2D) + shapeProperties.Append(presetGeometry) + + ' Adds all elements to the slide's shape tree + picture.Append(nonVisualPictureProperties) + picture.Append(blipFill) + picture.Append(shapeProperties) + + shapeTree.Append(picture) + End Using + End Sub +End Module \ No newline at end of file diff --git a/samples/presentation/add_video/vb/add_video_vb.vbproj b/samples/presentation/add_video/vb/add_video_vb.vbproj new file mode 100644 index 00000000..9edc3769 --- /dev/null +++ b/samples/presentation/add_video/vb/add_video_vb.vbproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <RootNamespace>add_video_vb</RootNamespace> + <TargetFramework>net9.0</TargetFramework> + </PropertyGroup> + +</Project> diff --git a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj index b4b1d3ea..08847b93 100644 --- a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj +++ b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj @@ -1 +1,5 @@ -<Project Sdk="Microsoft.NET.Sdk" /> \ No newline at end of file +<Project Sdk="Microsoft.NET.Sdk"> + <ItemGroup> + <ProjectReference Include="..\..\get_the_titles_of_all_the_slides\vb\get_the_titles_of_all_the_slides_vb.vbproj" /> + </ItemGroup> +</Project> \ No newline at end of file diff --git a/samples/samples.sln b/samples/samples.sln index 79c210a2..79cc1e37 100644 --- a/samples/samples.sln +++ b/samples/samples.sln @@ -320,6 +320,10 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "working_with_tables_vb", "w EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "insert_a_picture_vb", "word\insert_a_picture\vb\insert_a_picture_vb.vbproj", "{6170C4E1-A109-435A-BF59-026C85B3BD9C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "add_video_cs", "presentation\add_video\cs\add_video_cs.csproj", "{9350E344-D11D-4496-9092-9BA18FC65175}" +EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "add_video_vb", "presentation\add_video\vb\add_video_vb.vbproj", "{437E22AF-37F2-4D91-B508-2317AD5368BE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -938,6 +942,14 @@ Global {6170C4E1-A109-435A-BF59-026C85B3BD9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {6170C4E1-A109-435A-BF59-026C85B3BD9C}.Release|Any CPU.ActiveCfg = Release|Any CPU {6170C4E1-A109-435A-BF59-026C85B3BD9C}.Release|Any CPU.Build.0 = Release|Any CPU + {9350E344-D11D-4496-9092-9BA18FC65175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9350E344-D11D-4496-9092-9BA18FC65175}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9350E344-D11D-4496-9092-9BA18FC65175}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9350E344-D11D-4496-9092-9BA18FC65175}.Release|Any CPU.Build.0 = Release|Any CPU + {437E22AF-37F2-4D91-B508-2317AD5368BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {437E22AF-37F2-4D91-B508-2317AD5368BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {437E22AF-37F2-4D91-B508-2317AD5368BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {437E22AF-37F2-4D91-B508-2317AD5368BE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1095,6 +1107,8 @@ Global {A43A75AB-D6B6-4D31-99F7-6951AFEF502D} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F} {4EB1FCC9-E1E2-4D2A-ACF9-A3A31AA947A5} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F} {6170C4E1-A109-435A-BF59-026C85B3BD9C} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F} + {9350E344-D11D-4496-9092-9BA18FC65175} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D} + {437E22AF-37F2-4D91-B508-2317AD5368BE} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {721B3030-08D7-4412-9087-D1CFBB3F5046} From 798e91fd1ea2f8841bb05dda6bec801cebec915f Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Fri, 28 Mar 2025 09:31:50 +0000 Subject: [PATCH 02/14] added code snipets --- ...dd-a-video-to-a-slide-in-a-presentation.md | 125 +++++++----------- samples/presentation/add_video/cs/Program.cs | 18 ++- samples/presentation/add_video/vb/Program.vb | 17 ++- 3 files changed, 71 insertions(+), 89 deletions(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index c705c3e1..845a53f7 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -47,121 +47,92 @@ you want to open the document. ## The Structure of the Video From File -The basic document structure of a PresentationML document consists of a -number of parts, among which is the Shape Tree (`<spTree/>`) element. +The PresentationML document consists of a number of parts, among which is the Picture (`<pic/>`) element. -The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification -introduces the overall form of a `PresentationML` package. +The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification introduces the overall form of a `PresentationML` package. -> This element specifies the presence of a video file. It is defined -> within the non-visual properties of an object. The video is attached to an object, representing it -> shall be attached to an object as this is how it is represented within -> the document. The actual playing of the video however is done within -> the timing node list that is specified under the timing element. -> -> [*Example*: Consider the following ``Picture`` object that has a video attached to it. +Video File (`<videoFile/>`) specifies the presence of a video file. It is defined within the non-visual properties of an object. The video is attached to an object, representing it shall be attached to an object as this is how it is represented within the document. The actual playing of the video however is done within the timing node list that is specified under the timing element. + +Consider the following ``Picture`` object that has a video attached to it. ```xml - <p:sld> - <p:cSld> - <p:spTree> - <p:nvGrpSpPr> - .. - </p:nvGrpSpPr> - <p:grpSpPr> - .. - </p:grpSpPr> - <p:sp> - .. - </p:sp> - </p:spTree> - </p:cSld> - .. - </p:sld> +<p:pic> + <p:nvPicPr> + <p:cNvPr id="7" name="Rectangle 6"> + <a:hlinkClick r:id="" action="ppaction://media"/> + </p:cNvPr> + <p:cNvPicPr> + <a:picLocks noRot="1"/> + </p:cNvPicPr> + <p:nvPr> + <a:videoFile r:link="rId1"/> + </p:nvPr> + </p:nvPicPr> +</p:pic> ``` -> In the above example the shape tree specifies all the shape properties -> for this slide. *end example*] -> -> © [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)] - -The following table lists the child elements of the Shape Tree along -with the description of each. +In the above example, we see that there is a single videoFile element attached to this picture. This picture is placed within the document just as a normal picture or shape would be. The id of this picture, namely 7 in this case, is used to refer to this videoFile element from within the timing node list. The Linked relationship id is used to retrieve the actual video file for playback purposes. -| Element | Description | -|---|---| -| cxnSp | Connection Shape | -| extLst | Extension List with Modification Flag | -| graphicFrame | Graphic Frame | -| grpSp | Group Shape | -| grpSpPr | Group Shape Properties | -| nvGrpSpPr | Non-Visual Properties for a Group Shape | -| pic | Picture | -| sp | Shape | +© [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)] -The following XML Schema fragment defines the contents of this element. +The following XML Schema fragment defines the contents of videoFile. ```xml - <complexType name="CT_GroupShape"> - <sequence> - <element name="nvGrpSpPr" type="CT_GroupShapeNonVisual" minOccurs="1" maxOccurs="1"/> - <element name="grpSpPr" type="a:CT_GroupShapeProperties" minOccurs="1" maxOccurs="1"/> - <choice minOccurs="0" maxOccurs="unbounded"> - <element name="sp" type="CT_Shape"/> - <element name="grpSp" type="CT_GroupShape"/> - <element name="graphicFrame" type="CT_GraphicalObjectFrame"/> - <element name="cxnSp" type="CT_Connector"/> - <element name="pic" type="CT_Picture"/> - </choice> - <element name="extLst" type="CT_ExtensionListModify" minOccurs="0" maxOccurs="1"/> - </sequence> - </complexType> +<xsd:complexType name="CT_TLMediaNodeVideo"> + <xsd:sequence> + <xsd:element name="cMediaNode" type="CT_TLCommonMediaNodeData" minOccurs="1" maxOccurs="1"/> + </xsd:sequence> + <xsd:attribute name="fullScrn" type="xsd:boolean" use="optional" default="false"/> +</xsd:complexType> ``` ## How the Sample Code Works After opening the presentation file for read/write access in the `using` statement, the code gets the presentation part from the presentation document. Then it gets the relationship ID of -the first slide, and gets the slide part from the relationship ID. +the last slide, and gets the slide part from the relationship ID. -> [!NOTE] -> The test file must have a shape on the first slide. ### [C#](#tab/cs-2) -[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet2)] +[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet2)] ### [Visual Basic](#tab/vb-2) -[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet2)] +[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet2)] *** +The code first creates a media data part for the video file to be added. With the video file stream open, it feeds the media data part object. Next, video and media relationship references are added to the slide using the provided embedId for future reference to the video file and mediaEmbedId for media reference. -The code then gets the shape tree that contains the shape whose fill -color is to be changed, and gets the first shape in the shape tree. It -then gets the shape properties of the shape and the solid fill reference of the shape properties, -and assigns a new fill color to the shape. There is no need to explicitly -save the file when inside of a using. +An image part is then added with a sample picture to be used as a placeholder for the video. A picture object is created with various elements, such as Non-Visual Drawing Properties (<cNvPr/>), which specify non-visual canvas properties. This allows for additional information that does not affect the appearance of the picture to be stored. The <videoFile/> element, explained above, is also included. The HyperLinkOnClick (<hlinkClick/>) element specifies the on-click hyperlink information to be applied to a run of text or image. When the hyperlink text or image is clicked, the link is fetched. Non-Visual Picture Drawing Properties (<cNvPicPr/>) specify the non-visual properties for the picture canvas. For a detailed explanation of the elements used, please refer to [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] ### [C#](#tab/cs-3) -[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet3)] +[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet3)] ### [Visual Basic](#tab/vb-3) -[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet3)] +[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet3)] *** +Next Media(CT_Media) element is created with use of previously referenced mediaEmbedId(Embedded Picture Reference). Blip element is also added, this element specifies the existence of an image (binary large image or picture) and contains a reference to the image data. Blip's Embed attribute is used to specify an placeholder image in the Image Part created previously. + +### [C#](#tab/cs-4) +[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet4)] + +### [Visual Basic](#tab/vb-4) +[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet4)] +*** + +All other elements such Offset(`<off/>`), Stretch(`<stretch/>`), fillRectangle(`<fillRect/>`), are appended to the ShapeProperties(`<spPr/>`) and ShapeProperties are appended to the Picture element(`<pic/>`). Finally the picture element that incudes video is added to the ShapeTree(`<sp/>`) of the slide. + +Following is the complete sample code that you can use to add video to the slide. ## Sample Code -Following is the complete sample code that you can use to change the -fill color of a shape in a presentation. ### [C#](#tab/cs) -[!code-csharp[](../../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs#snippet0)] +[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet0)] ### [Visual Basic](#tab/vb) -[!code-vb[](../../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb#snippet0)] +[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet0)] *** ## See also - - - [Open XML SDK class library reference](/office/open-xml/open-xml-sdk) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index 29dd7c71..753c883c 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -12,7 +12,7 @@ using DocumentFormat.OpenXml.Packaging; using ApplicationNonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties; - +// <Snippet0> AddVideo(args[0], args[1], args[2]); static void AddVideo(string filePath, string videoFilePath, string coverPicPath) @@ -29,7 +29,7 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) { throw new NullReferenceException("Presenation Part is empty or there are no slides in it"); } - + // <Snippet2> //Get presentation part PresentationPart presentationPart = presentationDocument.PresentationPart; @@ -38,7 +38,7 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) //Get relationsipId of the last slide - string? videoSldRelationshipId = ((SlideId) slidesIds[0]).RelationshipId; + string? videoSldRelationshipId = ((SlideId) slidesIds[slidesIds.ToArray().Length - 1]).RelationshipId; if (videoSldRelationshipId == null) { @@ -47,7 +47,9 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) //Get slide part by relationshipID SlidePart? slidePart = (SlidePart) presentationPart.GetPartById(videoSldRelationshipId); + // </Snippet2> + // <Snippet3> // Create video Media Data Part (content type, extension) MediaDataPart mediaDataPart = presentationDocument.CreateMediaDataPart("video/mp4", ".mp4"); @@ -68,13 +70,15 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) ApplicationNonVisualDrawingProperties appNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties(); appNonVisualDrawingProperties.Append(videoFromFile); + + //adds sample image to the slide with id to be used as reference in blip ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, imgEmbedId); using (Stream data = File.OpenRead(coverPicPath)) { imagePart.FeedData(data); } - + if (slidePart!.Slide!.CommonSlideData!.ShapeTree == null) { throw new NullReferenceException("Presenation shape tree is empty"); @@ -97,7 +101,9 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) ApplicationNonVisualDrawingPropertiesExtensionList appNonVisualDrawingPropertiesExtensionList = new ApplicationNonVisualDrawingPropertiesExtensionList(); ApplicationNonVisualDrawingPropertiesExtension appNonVisualDrawingPropertiesExtension = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" }; + // </Snippet3> + // <Snippet4> P14.Media media = new() { Embed = mediaEmbedId }; media.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); @@ -112,6 +118,7 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) //Prepare shape properties to display picture BlipFill blipFill = new BlipFill(); A.Blip blip = new A.Blip() { Embed = imgEmbedId }; + // </Snippet4> A.Stretch stretch = new A.Stretch(); A.FillRectangle fillRectangle = new A.FillRectangle(); @@ -140,4 +147,5 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) shapeTree.Append(picture); } -} \ No newline at end of file +} +// </Snippet0> \ No newline at end of file diff --git a/samples/presentation/add_video/vb/Program.vb b/samples/presentation/add_video/vb/Program.vb index 5d2574db..dc44b108 100644 --- a/samples/presentation/add_video/vb/Program.vb +++ b/samples/presentation/add_video/vb/Program.vb @@ -12,7 +12,7 @@ Imports BlipFill = DocumentFormat.OpenXml.Presentation.BlipFill Imports DocumentFormat.OpenXml.Packaging Imports ApplicationNonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties Imports System.IO - +' <Snippet0> Module Program Sub Main(args As String()) AddVideo(args(0), args(1), args(2)) @@ -29,7 +29,7 @@ Module Program If presentationDocument.PresentationPart Is Nothing OrElse presentationDocument.PresentationPart.Presentation.SlideIdList Is Nothing Then Throw New NullReferenceException("Presentation Part is empty or there are no slides in it") End If - + ' <Snippet2> ' Get presentation part Dim presentationPart As PresentationPart = presentationDocument.PresentationPart @@ -37,7 +37,7 @@ Module Program Dim slidesIds As OpenXmlElementList = presentationPart.Presentation.SlideIdList.ChildElements ' Get relationshipId of the last slide - Dim videoSldRelationshipId As String = CType(slidesIds(0), SlideId).RelationshipId + Dim videoSldRelationshipId As String = CType(slidesIds(slidesIds.ToArray().Length - 1), SlideId).RelationshipId If videoSldRelationshipId Is Nothing Then Throw New NullReferenceException("Slide id not found") @@ -45,7 +45,8 @@ Module Program ' Get slide part by relationshipID Dim slidePart As SlidePart = CType(presentationPart.GetPartById(videoSldRelationshipId), SlidePart) - + ' </Snippet2> + ' <Snippet3> ' Create video Media Data Part (content type, extension) Dim mediaDataPart As MediaDataPart = presentationDocument.CreateMediaDataPart("video/mp4", ".mp4") @@ -104,7 +105,8 @@ Module Program Dim appNonVisualDrawingPropertiesExtension As New ApplicationNonVisualDrawingPropertiesExtension() With { .Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" } - + ' </Snippet3> + ' <Snippet4> Dim media As New P14.Media() With { .Embed = mediaEmbedId } @@ -123,7 +125,7 @@ Module Program Dim blip As New A.Blip() With { .Embed = imgEmbedId } - + ' </Snippet4> Dim stretch As New A.Stretch() Dim fillRectangle As New A.FillRectangle() Dim transform2D As New A.Transform2D() @@ -159,4 +161,5 @@ Module Program shapeTree.Append(picture) End Using End Sub -End Module \ No newline at end of file +End Module +' </Snippet0> \ No newline at end of file From 86255f99110945b037facce9a7af272baa6ee62e Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Fri, 28 Mar 2025 09:50:00 +0000 Subject: [PATCH 03/14] fixed build warnings --- .../how-to-add-a-video-to-a-slide-in-a-presentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index 845a53f7..7f6c2dee 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -102,7 +102,7 @@ the last slide, and gets the slide part from the relationship ID. The code first creates a media data part for the video file to be added. With the video file stream open, it feeds the media data part object. Next, video and media relationship references are added to the slide using the provided embedId for future reference to the video file and mediaEmbedId for media reference. -An image part is then added with a sample picture to be used as a placeholder for the video. A picture object is created with various elements, such as Non-Visual Drawing Properties (<cNvPr/>), which specify non-visual canvas properties. This allows for additional information that does not affect the appearance of the picture to be stored. The <videoFile/> element, explained above, is also included. The HyperLinkOnClick (<hlinkClick/>) element specifies the on-click hyperlink information to be applied to a run of text or image. When the hyperlink text or image is clicked, the link is fetched. Non-Visual Picture Drawing Properties (<cNvPicPr/>) specify the non-visual properties for the picture canvas. For a detailed explanation of the elements used, please refer to [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] +An image part is then added with a sample picture to be used as a placeholder for the video. A picture object is created with various elements, such as Non-Visual Drawing Properties (`<cNvPr/>`), which specify non-visual canvas properties. This allows for additional information that does not affect the appearance of the picture to be stored. The `<videoFile/>` element, explained above, is also included. The HyperLinkOnClick (`<hlinkClick/>`) element specifies the on-click hyperlink information to be applied to a run of text or image. When the hyperlink text or image is clicked, the link is fetched. Non-Visual Picture Drawing Properties (`<cNvPicPr/>`) specify the non-visual properties for the picture canvas. For a detailed explanation of the elements used, please refer to [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] ### [C#](#tab/cs-3) [!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet3)] From c42167162bb34a495c756540fae775412d529605 Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Fri, 28 Mar 2025 10:04:19 +0000 Subject: [PATCH 04/14] revert unintended change in insert_a_new_slideto_cs.csproj --- .../insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj index 08847b93..6b512ec9 100644 --- a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj +++ b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj @@ -1,5 +1 @@ -<Project Sdk="Microsoft.NET.Sdk"> - <ItemGroup> - <ProjectReference Include="..\..\get_the_titles_of_all_the_slides\vb\get_the_titles_of_all_the_slides_vb.vbproj" /> - </ItemGroup> -</Project> \ No newline at end of file +<Project Sdk="Microsoft.NET.Sdk" /> From df45c27ea2fa59d5e3dc7a65abfd3afaf794c1a6 Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Fri, 28 Mar 2025 10:05:39 +0000 Subject: [PATCH 05/14] Reverted to match main insert_a_new_slideto_cs.csproj --- .../insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj index 6b512ec9..9609c619 100644 --- a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj +++ b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj @@ -1 +1,2 @@ <Project Sdk="Microsoft.NET.Sdk" /> + From fc7e950ce08241a67aa11b3383c8b06a9518f1f7 Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Fri, 28 Mar 2025 14:02:24 +0000 Subject: [PATCH 06/14] removed .Net framework target --- samples/presentation/add_video/cs/add_video_cs.csproj | 11 +---------- samples/presentation/add_video/vb/add_video_vb.vbproj | 10 +--------- .../cs/insert_a_new_slideto_cs.csproj | 6 +----- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/samples/presentation/add_video/cs/add_video_cs.csproj b/samples/presentation/add_video/cs/add_video_cs.csproj index fd4bd08d..e43252bf 100644 --- a/samples/presentation/add_video/cs/add_video_cs.csproj +++ b/samples/presentation/add_video/cs/add_video_cs.csproj @@ -1,10 +1 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <TargetFramework>net9.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - </PropertyGroup> - -</Project> +<Project Sdk="Microsoft.NET.Sdk"/> \ No newline at end of file diff --git a/samples/presentation/add_video/vb/add_video_vb.vbproj b/samples/presentation/add_video/vb/add_video_vb.vbproj index 9edc3769..e43252bf 100644 --- a/samples/presentation/add_video/vb/add_video_vb.vbproj +++ b/samples/presentation/add_video/vb/add_video_vb.vbproj @@ -1,9 +1 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <RootNamespace>add_video_vb</RootNamespace> - <TargetFramework>net9.0</TargetFramework> - </PropertyGroup> - -</Project> +<Project Sdk="Microsoft.NET.Sdk"/> \ No newline at end of file diff --git a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj index 08847b93..b4b1d3ea 100644 --- a/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj +++ b/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj @@ -1,5 +1 @@ -<Project Sdk="Microsoft.NET.Sdk"> - <ItemGroup> - <ProjectReference Include="..\..\get_the_titles_of_all_the_slides\vb\get_the_titles_of_all_the_slides_vb.vbproj" /> - </ItemGroup> -</Project> \ No newline at end of file +<Project Sdk="Microsoft.NET.Sdk" /> \ No newline at end of file From 62a8d4ccbfc307e27710b904a2b8b94ab671ce4e Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Mon, 31 Mar 2025 11:19:07 +0100 Subject: [PATCH 07/14] fixing typo --- .../how-to-add-a-video-to-a-slide-in-a-presentation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index 7f6c2dee..fdda8b70 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -11,7 +11,7 @@ ms.suite: office ms.author: o365devx author: o365devx ms.topic: conceptual -ms.date: 02/25/2025 +ms.date: 03/31/2025 ms.localizationpriority: medium --- @@ -51,7 +51,7 @@ The PresentationML document consists of a number of parts, among which is the Pi The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification introduces the overall form of a `PresentationML` package. -Video File (`<videoFile/>`) specifies the presence of a video file. It is defined within the non-visual properties of an object. The video is attached to an object, representing it shall be attached to an object as this is how it is represented within the document. The actual playing of the video however is done within the timing node list that is specified under the timing element. +Video File (`<videoFile/>`) specifies the presence of a video file. It is defined within the non-visual properties of an object. The video shall be attached to an object as this is how it is represented within the document. The actual playing of the video however is done within the timing node list that is specified under the timing element. Consider the following ``Picture`` object that has a video attached to it. From 797853973266ad580384c4185d76a899d67afc1b Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Tue, 1 Apr 2025 11:22:27 +0100 Subject: [PATCH 08/14] Update samples/presentation/add_video/cs/Program.cs Typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- samples/presentation/add_video/cs/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index 753c883c..e2696a57 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -27,7 +27,7 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) if (presentationDocument.PresentationPart == null || presentationDocument.PresentationPart.Presentation.SlideIdList == null) { - throw new NullReferenceException("Presenation Part is empty or there are no slides in it"); + throw new NullReferenceException("Presentation Part is empty or there are no slides in it"); } // <Snippet2> //Get presentation part From bc6678774451701fe290eb28e23e8d37eed9922a Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Tue, 1 Apr 2025 11:22:49 +0100 Subject: [PATCH 09/14] Update samples/presentation/add_video/cs/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- samples/presentation/add_video/cs/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index e2696a57..45c0ca1c 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -81,7 +81,7 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) if (slidePart!.Slide!.CommonSlideData!.ShapeTree == null) { - throw new NullReferenceException("Presenation shape tree is empty"); + throw new NullReferenceException("Presentation shape tree is empty"); } //Getting existing shape tree object from PowerPoint From 83d351e97b51f2edeffa887272b40ab843dec7d3 Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Tue, 1 Apr 2025 11:22:58 +0100 Subject: [PATCH 10/14] Update samples/presentation/add_video/cs/Program.cs Co-authored-by: Taylor Southwick <tasou@microsoft.com> --- samples/presentation/add_video/cs/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index 45c0ca1c..1b5b877e 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -69,8 +69,6 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) ApplicationNonVisualDrawingProperties appNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties(); appNonVisualDrawingProperties.Append(videoFromFile); - - //adds sample image to the slide with id to be used as reference in blip ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, imgEmbedId); From b869034c0529cf5e9f2caeb3c2a9b2802f454c5c Mon Sep 17 00:00:00 2001 From: Mariusz <mkaszewiak@microsoft.com> Date: Tue, 1 Apr 2025 11:23:32 +0100 Subject: [PATCH 11/14] Update samples/presentation/add_video/cs/Program.cs Co-authored-by: Taylor Southwick <tasou@microsoft.com> --- samples/presentation/add_video/cs/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index 1b5b877e..c8fb10f9 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -143,7 +143,6 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) picture.Append(shapeProperties); shapeTree.Append(picture); - } } // </Snippet0> \ No newline at end of file From 8db9e3b3cd1dcd2462d61548c7d1e47c0639c5be Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Tue, 1 Apr 2025 12:14:39 +0100 Subject: [PATCH 12/14] applied comments --- .../how-to-add-a-video-to-a-slide-in-a-presentation.md | 4 ++-- samples/presentation/add_video/cs/Program.cs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index fdda8b70..11c881bb 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -23,9 +23,9 @@ programmatically. ## Getting a Presentation Object -In the Open XML SDK, the `PresentationDocument` class represents a +In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a presentation document package. To work with a presentation document, -first create an instance of the `PresentationDocument` class, and then work with +first create an instance of the **PresentationDocument* class, and then work with that instance. To create the class instance from the document call the `Open` method that uses a file path, and a Boolean value as the second parameter to specify whether a document is diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index c8fb10f9..666195e7 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -11,6 +11,9 @@ using BlipFill = DocumentFormat.OpenXml.Presentation.BlipFill; using DocumentFormat.OpenXml.Packaging; using ApplicationNonVisualDrawingProperties = DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties; +using System; +using System.IO; +using System.Linq; // <Snippet0> AddVideo(args[0], args[1], args[2]); From 4283f962888ff9416a8b4047a1bd2b60f5e0ba7f Mon Sep 17 00:00:00 2001 From: Alfred Hellstern <alfredh@microsoft.com> Date: Tue, 1 Apr 2025 14:11:24 -0700 Subject: [PATCH 13/14] Update how-to-add-a-video-to-a-slide-in-a-presentation.md fixed typos --- .../how-to-add-a-video-to-a-slide-in-a-presentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index 11c881bb..a56cfea1 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -111,7 +111,7 @@ An image part is then added with a sample picture to be used as a placeholder fo [!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet3)] *** -Next Media(CT_Media) element is created with use of previously referenced mediaEmbedId(Embedded Picture Reference). Blip element is also added, this element specifies the existence of an image (binary large image or picture) and contains a reference to the image data. Blip's Embed attribute is used to specify an placeholder image in the Image Part created previously. +Next Media(CT_Media) element is created with use of previously referenced mediaEmbedId(Embedded Picture Reference). The Blip element is also added; this element specifies the existence of an image (binary large image or picture) and contains a reference to the image data. Blip's Embed attribute is used to specify a placeholder image in the Image Part created previously. ### [C#](#tab/cs-4) [!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet4)] From b35f7d881f98efaeeb347f682194c3d4c975eec7 Mon Sep 17 00:00:00 2001 From: MARIUSZ KASZEWIAK <mkaszewiak@microsoft.com> Date: Thu, 3 Apr 2025 10:36:26 +0100 Subject: [PATCH 14/14] Updated ms.assetid --- .../how-to-add-a-video-to-a-slide-in-a-presentation.md | 6 +++--- samples/presentation/add_video/cs/Program.cs | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md index a56cfea1..75566fe5 100644 --- a/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md +++ b/docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md @@ -4,14 +4,14 @@ api_name: - Microsoft.Office.DocumentFormat.OpenXML.Packaging api_type: - schema -ms.assetid: 403abe97-7ab2-40ba-92c0-d6312a6d10c8 +ms.assetid: 536c94b5-dd25-4173-ad6a-b72b95dd7f31 title: 'How to: Add a video to a slide in a presentation' ms.suite: office ms.author: o365devx author: o365devx ms.topic: conceptual -ms.date: 03/31/2025 +ms.date: 04/03/2025 ms.localizationpriority: medium --- @@ -27,7 +27,7 @@ In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocu presentation document package. To work with a presentation document, first create an instance of the **PresentationDocument* class, and then work with that instance. To create the class instance from the document call the -`Open` method that uses a file path, and a +<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method that uses a file path, and a Boolean value as the second parameter to specify whether a document is editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following `using` statement. In this code, the file diff --git a/samples/presentation/add_video/cs/Program.cs b/samples/presentation/add_video/cs/Program.cs index 666195e7..f03c8834 100644 --- a/samples/presentation/add_video/cs/Program.cs +++ b/samples/presentation/add_video/cs/Program.cs @@ -39,7 +39,6 @@ static void AddVideo(string filePath, string videoFilePath, string coverPicPath) //Get slides ids. OpenXmlElementList slidesIds = presentationPart.Presentation.SlideIdList.ChildElements; - //Get relationsipId of the last slide string? videoSldRelationshipId = ((SlideId) slidesIds[slidesIds.ToArray().Length - 1]).RelationshipId;