Skip to content

EndnotesPart.AddHyperlinkRelationship not generating proper endnotes.xml.rels #1778

@bhargavgaglani07

Description

@bhargavgaglani07

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();
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions