using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open("Test.docx", false)) { MainDocumentPart mainPart = wordDoc.MainDocumentPart; CustomXmlPart customXmlPart = mainPart.CustomXmlParts.FirstOrDefault(); if (customXmlPart != null) { string id = mainPart.GetIdOfPart(customXmlPart); Console.WriteLine("The ID of the CustomXMLPart is: {0}", id); } }
using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using (PresentationDocument pptDoc = PresentationDocument.Open("Test.pptx", false)) { MainDocumentPart mainPart = pptDoc.PresentationPart.GetPartById("rId1").OpenXmlPart as MainDocumentPart; EmbeddedPackagePart embeddedPackagePart = mainPart.EmbeddedPackageParts.FirstOrDefault(); if (embeddedPackagePart != null) { string id = mainPart.GetIdOfPart(embeddedPackagePart); Console.WriteLine("The ID of the EmbeddedPackagePart is: {0}", id); } }In this example, we open a PowerPoint document, retrieve its MainDocumentPart via the PresentationPart, and get the first EmbeddedPackagePart within it. We then use the GetIdOfPart method to retrieve the ID of the EmbeddedPackagePart and display it on the console. Overall, the MainDocumentPart.GetIdOfPart method is a useful tool for working with OpenXML documents, and is typically used in conjunction with the OpenXML SDK library to manipulate and create documents programmatically.