public Paragraph AppendPicture(Picture p)
{
// Convert the path of this mainPart to its equilivant rels file path.
string path = mainPart.Uri.OriginalString.Replace("/word/", "");
Uri rels_path = new Uri("/word/_rels/" + path + ".rels", UriKind.Relative);
// Check to see if the rels file exists and create it if not.
if (!Document.package.PartExists(rels_path))
HelperFunctions.CreateRelsPackagePart(Document, rels_path);
// Check to see if a rel for this Picture exists, create it if not.
var Id = GetOrGenerateRel(p);
// Add the Picture Xml to the end of the Paragragraph Xml.
Xml.Add(p.Xml);
// Extract the attribute id from the Pictures Xml.
XAttribute a_id =
(
from e in Xml.Elements().Last().Descendants()
where e.Name.LocalName.Equals("blip")
select e.Attribute(XName.Get("embed", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"))
).Single();
// Set its value to the Pictures relationships id.
a_id.SetValue(Id);
// For formatting such as .Bold()
this.runs = Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).Reverse().Take(p.Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).Count()).ToList();
return this;
}