Open XML SDK - Word 2007 Uri Issue
-
I've just lost a day and a half of my working life trying to track down a bug which was causing word documents i am changing to include a mail merge source to error when opened in word 2007. The documents work fine in word 2010. After an awful lot of digging, I've tracked the issue down to the URI for the mdb file that is the data source for the merge. My non working in 2007 code was as follows:
using (var docx = WordProcessingDocument.Open(filePath, true))
{
FileInfo mdbFile = FileHelper.GetResourceFile("Merge.mdb");
Uri mdbUri = new Uri(mdbFile.FullName, UriKind.Absolute);var settings = DocHelper.GetOrCreateSettingsPart(document); settings.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/mailMergeSource", mdbUri, id1);
}
After an awful lot of checking i found that the relationship file was recording the uri without a leading "file:///", some more looking into this it appears that the openXML SDK is writing out the OrigionalString. The change i had to make to my code for it to work was as follows:
Uri mdbUri = new Uri("file:///" + mdbFile.FullName, UriKind.Absolute);
I guess my question is, was i doing something wrong when working with the Uri or is this something that the SDK is not getting right. Additionally i really hope it is not a bug that was found, and fixed in Office 2010 by working with the Uri missing the "file:///" prefix insted of changing the SDK to write out Uri.ToString();