Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

EndnotesPart.AddHyperlinkRelationship not generating proper endnotes.xml.rels

Open bhargavgaglani07 opened this issue 1 year ago • 4 comments

Describe the bug Adding an endnote having hyperlink into a document having no existing relationship for an endnote part is not generating proper endnotes.xml.rels file due to which generated document cannot be open using MS word or any other related application.

Screenshots

image image

To Reproduce Kindly run attached console app to reproduce the issue. EndnotesWithURLIssue.zip

Observed behavior If same code is executed (EndnotesPart.AddHyperlinkRelationship) for document already having an existing relationship present for endnotepart then generated document can be opened.

Expected behavior EndnotesPart.AddHyperlinkRelationship should create a proper endnotes.xml.rels if not present.

Desktop (please complete the following information):

  • OS: windows 10
  • Office version: 16.0.17628.20188
  • .NET Target: 4.8
  • DocumentFormat.OpenXml Version: 2.5.0, 3.1.0

Debug Info Adding below code before adding hyperlink relationship fixes the issue.

if(!document.Package.PartExists(new Uri("/word/_rels/endnotes.xml.rels", UriKind.Relative)))
{
    var part = document.Package.CreatePart(new Uri("/word/_rels/endnotes.xml.rels", UriKind.Relative), "application/vnd.openxmlformats-package.relationships+xml");
    part.Package.Flush();
}

bhargavgaglani07 avatar Aug 26 '24 09:08 bhargavgaglani07