protected void clonePackageRelationship(DocX remote_document, PackagePart pp, XDocument remote_mainDoc)
{
string url = pp.Uri.OriginalString.Replace("/", "");
var remote_rels = remote_document.mainPart.GetRelationships();
foreach (var remote_rel in remote_rels)
{
if (url.Equals("word" + remote_rel.TargetUri.OriginalString.Replace("/", "")))
{
String remote_Id = remote_rel.Id;
String local_Id = mainPart.CreateRelationship(remote_rel.TargetUri, remote_rel.TargetMode, remote_rel.RelationshipType).Id;
// Replace all instances of remote_Id in the local document with local_Id
var elems = remote_mainDoc.Descendants(XName.Get("blip", a.NamespaceName));
foreach (var elem in elems)
{
XAttribute embed = elem.Attribute(XName.Get("embed", r.NamespaceName));
if (embed != null && embed.Value == remote_Id)
{
embed.SetValue(local_Id);
}
}
// Replace all instances of remote_Id in the local document with local_Id (for shapes as well)
var v_elems = remote_mainDoc.Descendants(XName.Get("imagedata", v.NamespaceName));
foreach (var elem in v_elems)
{
XAttribute id = elem.Attribute(XName.Get("id", r.NamespaceName));
if (id != null && id.Value == remote_Id)
{
id.SetValue(local_Id);
}
}
break;
}
}
}