Skip to content

Commit 46f6b5c

Browse files
authored
Merge branch 'main' into addTransitionToTheSlide
2 parents fa8ce02 + 17d5477 commit 46f6b5c

13 files changed

+516
-25
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
3+
api_name:
4+
- Microsoft.Office.DocumentFormat.OpenXML.Packaging
5+
api_type:
6+
- schema
7+
ms.assetid: 536c94b5-dd25-4173-ad6a-b72b95dd7f31
8+
title: 'How to: Add a video to a slide in a presentation'
9+
ms.suite: office
10+
11+
ms.author: o365devx
12+
author: o365devx
13+
ms.topic: conceptual
14+
ms.date: 04/03/2025
15+
ms.localizationpriority: medium
16+
---
17+
18+
# Add a video to a slide in a presentation
19+
20+
This topic shows how to use the classes in the Open XML SDK for
21+
Office to add a video to the first slide in a presentation
22+
programmatically.
23+
24+
## Getting a Presentation Object
25+
26+
In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a
27+
presentation document package. To work with a presentation document,
28+
first create an instance of the **PresentationDocument** class, and then work with
29+
that instance. To create the class instance from the document call the
30+
<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method that uses a file path, and a
31+
Boolean value as the second parameter to specify whether a document is
32+
editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
33+
`using` statement. In this code, the file
34+
parameter is a string that represents the path for the file from which
35+
you want to open the document.
36+
37+
### [C#](#tab/cs-1)
38+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet1)]
39+
40+
### [Visual Basic](#tab/vb-1)
41+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet1)]
42+
***
43+
44+
45+
[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`.
46+
47+
48+
## The Structure of the Video From File
49+
50+
The PresentationML document consists of a number of parts, among which is the Picture (`<pic/>`) element.
51+
52+
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.
53+
54+
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.
55+
56+
Consider the following `Picture` object that has a video attached to it.
57+
58+
```xml
59+
<p:pic>
60+
<p:nvPicPr>
61+
<p:cNvPr id="7" name="Rectangle 6">
62+
<a:hlinkClick r:id="" action="ppaction://media"/>
63+
</p:cNvPr>
64+
<p:cNvPicPr>
65+
<a:picLocks noRot="1"/>
66+
</p:cNvPicPr>
67+
<p:nvPr>
68+
<a:videoFile r:link="rId1"/>
69+
</p:nvPr>
70+
</p:nvPicPr>
71+
</p:pic>
72+
```
73+
74+
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.
75+
76+
&copy; [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)]
77+
78+
The following XML Schema fragment defines the contents of videoFile.
79+
80+
```xml
81+
<xsd:complexType name="CT_TLMediaNodeVideo">
82+
<xsd:sequence>
83+
<xsd:element name="cMediaNode" type="CT_TLCommonMediaNodeData" minOccurs="1" maxOccurs="1"/>
84+
</xsd:sequence>
85+
<xsd:attribute name="fullScrn" type="xsd:boolean" use="optional" default="false"/>
86+
</xsd:complexType>
87+
```
88+
89+
## How the Sample Code Works
90+
91+
After opening the presentation file for read/write access in the `using` statement, the code gets the presentation
92+
part from the presentation document. Then it gets the relationship ID of
93+
the last slide, and gets the slide part from the relationship ID.
94+
95+
96+
### [C#](#tab/cs-2)
97+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet2)]
98+
99+
### [Visual Basic](#tab/vb-2)
100+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet2)]
101+
***
102+
103+
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.
104+
105+
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)]
106+
107+
### [C#](#tab/cs-3)
108+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet3)]
109+
110+
### [Visual Basic](#tab/vb-3)
111+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet3)]
112+
***
113+
114+
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.
115+
116+
### [C#](#tab/cs-4)
117+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet4)]
118+
119+
### [Visual Basic](#tab/vb-4)
120+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet4)]
121+
***
122+
123+
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.
124+
125+
Following is the complete sample code that you can use to add video to the slide.
126+
127+
## Sample Code
128+
129+
### [C#](#tab/cs)
130+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet0)]
131+
132+
### [Visual Basic](#tab/vb)
133+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet0)]
134+
***
135+
136+
## See also
137+
138+
- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)

docs/presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md renamed to docs/presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md

File renamed without changes.

docs/presentation/overview.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ This section provides how-to topics for working with presentation documents usin
2020

2121
## In this section
2222

23-
- [Structure of a PresentationML document](structure-of-a-presentationml-document.md)
23+
- [Structure of a PresentationML document](structure-of-a-presentationml-document.md)
2424

25+
26+
- [Add an audio file to a slide in a presentation](how-to-add-an-audio-to-a-slide-in-a-presentation.md)
27+
2528
- [Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)
2629

2730
- [Apply a theme to a presentation](how-to-apply-a-theme-to-a-presentation.md)
@@ -30,7 +33,7 @@ This section provides how-to topics for working with presentation documents usin
3033

3134
- [Create a presentation document by providing a file name](how-to-create-a-presentation-document-by-providing-a-file-name.md)
3235

33-
- [Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md)
36+
- [Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md)
3437

3538
- [Delete a slide from a presentation](how-to-delete-a-slide-from-a-presentation.md)
3639

@@ -40,7 +43,7 @@ This section provides how-to topics for working with presentation documents usin
4043

4144
- [Get all the text in all slides in a presentation](how-to-get-all-the-text-in-all-slides-in-a-presentation.md)
4245

43-
- [Get the titles of all the slides in a presentation](how-to-get-the-titles-of-all-the-slides-in-a-presentation.md)
46+
- [Get the titles of all the slides in a presentation](how-to-get-the-titles-of-all-the-slides-in-a-presentation.md)
4447

4548
- [Insert a new slide into a presentation](how-to-insert-a-new-slide-into-a-presentation.md)
4649

@@ -50,7 +53,8 @@ This section provides how-to topics for working with presentation documents usin
5053

5154
- [Open a presentation document for read-only access](how-to-open-a-presentation-document-for-read-only-access.md)
5255

53-
- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)
56+
- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)
57+
5458
- [Add a transition to a slides in a presentation](how-to-add-transitions-between-slides-in-a-presentation.md)
5559

5660
- [Working with animation](working-with-animation.md)

docs/presentation/working-with-comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ article.
193193
[About the Open XML SDK for Office](../about-the-open-xml-sdk.md)
194194
[How to: Create a Presentation by Providing a File Name](how-to-create-a-presentation-document-by-providing-a-file-name.md)
195195
[How to: Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)
196-
[How to: Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md)
196+
[How to: Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md)

docs/spreadsheet/overview.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,12 @@ This section provides how-to topics for working with spreadsheet documents using
2323

2424
- [Structure of a SpreadsheetML document](structure-of-a-spreadsheetml-document.md)
2525

26-
- [Working with the calculation chain](working-with-the-calculation-chain.md)
27-
28-
- [Working with conditional formatting](working-with-conditional-formatting.md)
29-
30-
- [Working with formulas](working-with-formulas.md)
31-
32-
- [Working with PivotTables](working-with-pivottables.md)
33-
34-
- [Working with the shared string table](working-with-the-shared-string-table.md)
35-
36-
- [Working with sheets](working-with-sheets.md)
37-
38-
- [Working with SpreadsheetML tables](working-with-tables.md)
26+
- [Add custom UI to a spreadsheet document](how-to-add-custom-ui-to-a-spreadsheet-document.md)
3927

4028
- [Calculate the sum of a range of cells in a spreadsheet document](how-to-calculate-the-sum-of-a-range-of-cells-in-a-spreadsheet-document.md)
4129

30+
- [Copy a Worksheet Using SAX (Simple API for XML)](how-to-copy-a-worksheet-with-sax.md)
31+
4232
- [Create a spreadsheet document by providing a file name](how-to-create-a-spreadsheet-document-by-providing-a-file-name.md)
4333

4434
- [Delete text from a cell in a spreadsheet document](how-to-delete-text-from-a-cell-in-a-spreadsheet.md)
@@ -69,6 +59,21 @@ This section provides how-to topics for working with spreadsheet documents using
6959

7060
- [Retrieve the values of cells in a spreadsheet document](how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md)
7161

62+
- [Retrieve a list of the worksheets in a spreadsheet document](how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md)
63+
64+
- [Working with the calculation chain](working-with-the-calculation-chain.md)
65+
66+
- [Working with conditional formatting](working-with-conditional-formatting.md)
67+
68+
- [Working with formulas](working-with-formulas.md)
69+
70+
- [Working with PivotTables](working-with-pivottables.md)
71+
72+
- [Working with the shared string table](working-with-the-shared-string-table.md)
73+
74+
- [Working with sheets](working-with-sheets.md)
75+
76+
- [Working with SpreadsheetML tables](working-with-tables.md)
7277

7378
## Related sections
7479

docs/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@
4848
href: presentation/how-to-add-an-audio-to-a-slide-in-a-presentation.md
4949
- name: Add a comment to a slide in a presentation
5050
href: presentation/how-to-add-a-comment-to-a-slide-in-a-presentation.md
51+
- name: Add a video to a slide in a presentation
52+
href: presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md
5153
- name: Apply a theme to a presentation
5254
href: presentation/how-to-apply-a-theme-to-a-presentation.md
5355
- name: Change the fill color of a shape in a presentation
5456
href: presentation/how-to-change-the-fill-color-of-a-shape-in-a-presentation.md
5557
- name: Create a presentation document by providing a file name
5658
href: presentation/how-to-create-a-presentation-document-by-providing-a-file-name.md
5759
- name: Delete all the comments by an author from all the slides in a presentation
58-
href: presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md
60+
href: presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md
5961
- name: Delete a slide from a presentation
6062
href: presentation/how-to-delete-a-slide-from-a-presentation.md
6163
- name: Get all the external hyperlinks in a presentation

docs/word/overview.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This section provides how-to topics for working with word processing documents u
2121

2222
## In this section
2323

24+
- [Structure of a WordprocessingML document](structure-of-a-wordprocessingml-document.md)
25+
2426
- [Accept all revisions in a word processing document](how-to-accept-all-revisions-in-a-word-processing-document.md)
2527

2628
- [Add tables to word processing documents](how-to-add-tables-to-word-processing-documents.md)
@@ -59,13 +61,15 @@ This section provides how-to topics for working with word processing documents u
5961

6062
- [Remove the headers and footers from a word processing document](how-to-remove-the-headers-and-footers-from-a-word-processing-document.md)
6163

64+
- [How to: Replace Text in a Word Document Using SAX (Simple API for XML)](how-to-replace-text-in-a-word-document-with-sax.md)
65+
6266
- [Replace the header in a word processing document](how-to-replace-the-header-in-a-word-processing-document.md)
6367

64-
- [Replace the styles parts in a word processing document](how-to-replace-the-styles-parts-in-a-word-processing-document.md)
68+
- [Replace the styles parts in a word processing document](how-to-replace-the-styles-parts-in-a-word-processing-document.md)
6569

66-
- [Retrieve comments from a word processing document](how-to-retrieve-comments-from-a-word-processing-document.md)
70+
- [Retrieve application property values from a Word document by using the Open XML API](how-to-retrieve-application-property-values-from-a-word-processing-document.md)
6771

68-
- [Retrieve property values from a Word document by using the Open XML API](how-to-retrieve-application-property-values-from-a-word-processing-document.md)
72+
- [Retrieve comments from a word processing document](how-to-retrieve-comments-from-a-word-processing-document.md)
6973

7074
- [Set a custom property in a word processing document](how-to-set-a-custom-property-in-a-word-processing-document.md)
7175

@@ -78,8 +82,7 @@ This section provides how-to topics for working with word processing documents u
7882
- [Working with runs](working-with-runs.md)
7983

8084
- [Working with WordprocessingML tables](working-with-wordprocessingml-tables.md)
81-
82-
- [Structure of a WordprocessingML document](structure-of-a-wordprocessingml-document.md)
85+
8386

8487
## Related sections
8588

samples/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ To add a sample, run the the following:
1010

1111
This will create an initial scaffold for a sample and add it to the solution file.
1212

13+
## Steps to Complete Before Creating a Pull Request:
14+
1. **Test Both Code Samples**
15+
Verify the functionality of both the C# and Visual Basic samples. To accelerate the process, you can use Copilot to translate the C# sample into Visual Basic. When writing code samples, avoid using var; instead, explicitly declare variable types.
16+
17+
2. **Validate Documentation with DocFX**
18+
Use the https://dotnet.github.io/docfx/ to ensure the generated documentation renders correctly and behaves as expected.
19+
20+
3. **Update the Table of Contents**
21+
Add a new entry to the toc.yml file so the content appears in the Navigation Pane on the Microsoft Learn website.
22+
23+
4. **Edit the Overview Page**
24+
Update the overview.md file with the new title and markdown file reference to ensure it appears in the overview section on Microsoft Learn. This file is located in one of the following directories: docs/presentation, docs/spreadsheet, or docs/word.
25+
26+
1327
## Migrate old samples
1428

1529
```powershell
1630
./migrate-sample.ps1 path-to-md-file
1731
```
1832

19-
This will do an inital extraction and clean up of the file, as well as add the code to the solution. Additional clean up will be necessary, but should be minimal.
33+
This will do an initial extraction and clean up of the file, as well as add the code to the solution. Additional clean up will be necessary, but should be minimal.
2034

2135
General changes to move a sample:
2236

0 commit comments

Comments
 (0)