protected virtual void WriteRelationshipPart(OpenXmlWriter writer)
        {
            List <OpenXmlPart> allParts = new List <OpenXmlPart>();

            allParts.AddRange(this.Parts);
            allParts.AddRange(this.ReferencedParts);

            // write part relationships
            if (allParts.Count > 0 || _externalRelationships.Count > 0)
            {
                string relFullName = Path.Combine(Path.Combine(this.TargetDirectoryAbsolute, REL_FOLDER), TargetName + TargetExt + REL_EXTENSION);
                writer.AddPart(relFullName);

                writer.WriteStartDocument();
                writer.WriteStartElement("Relationships", OpenXmlNamespaces.RelationsshipsPackage);

                foreach (ExternalRelationship rel in _externalRelationships)
                {
                    writer.WriteStartElement("Relationship", OpenXmlNamespaces.RelationsshipsPackage);
                    writer.WriteAttributeString("Id", rel.Id);
                    writer.WriteAttributeString("Type", rel.RelationshipType);
                    if (Uri.IsWellFormedUriString(rel.Target, UriKind.RelativeOrAbsolute))
                    {
                        if (rel.TargetUri.IsAbsoluteUri)
                        {
                            if (rel.TargetUri.IsFile)
                            {
                                //reform the URI path for Word
                                //Word does not accept forward slahes in the path of a local file
                                writer.WriteAttributeString("Target", "file:///" + rel.TargetUri.AbsolutePath.Replace("/", "\\"));
                            }
                            else
                            {
                                writer.WriteAttributeString("Target", rel.Target.ToString());
                            }
                        }
                        else
                        {
                            writer.WriteAttributeString("Target", Uri.EscapeUriString(rel.Target.ToString()));
                        }
                    }
                    else
                    {
                        writer.WriteAttributeString("Target", Uri.EscapeUriString(rel.Target));
                    }

                    writer.WriteAttributeString("TargetMode", "External");

                    writer.WriteEndElement();
                }

                foreach (OpenXmlPart part in allParts)
                {
                    writer.WriteStartElement("Relationship", OpenXmlNamespaces.RelationsshipsPackage);
                    writer.WriteAttributeString("Id", part.RelIdToString);
                    writer.WriteAttributeString("Type", part.RelationshipType);

                    // write the target relative to the current part
                    writer.WriteAttributeString("Target", "/" + part.TargetFullName.Replace('\\', '/'));

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }