openxml How to add an image to a Word Document. Add the image to the OpenXml structure


Example

private string AddGraph(WordprocessingDocument wpd, string filepath)
{
    ImagePart ip = wpd.MainDocumentPart.AddImagePart(ImagePartType.Jpeg);
    using (FileStream fs = new FileStream(filepath, FileMode.Open))
    {
        if (fs.Length == 0) return string.Empty;
        ip.FeedData(fs);
    }

    return wpd.MainDocumentPart.GetIdOfPart(ip);
}

In this case we use a FileStream to retrieve the image, but feedData(Stream) is waiting for any kind of Stream.