Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:16:59+00:00 2026-06-12T02:16:59+00:00

I am trying to use C# and Open XML to insert an image from

  • 0

I am trying to use C# and Open XML to insert an image from a url into a doc. The image may change so I don’t want to download it, I want it to remain an external reference.

I’ve found several examples like this one that allow me to add a local image:

http://msdn.microsoft.com/en-us/library/bb497430.aspx

How can I adapt that to take a URI? Or is there another approach altogether?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:17:00+00:00Added an answer on June 12, 2026 at 2:17 am

    You can add an external image to an word document via a quick parts field.
    For a description please see the following answer on superuser.

    To realize the described steps programmatically you have to
    use an external releationship to include an image from an URL.

    Here are the steps to accomplish this:

    1. Create an instance of the Picture class.
    2. Add a Shape to specify the style of the picture (width/height).
    3. Use the ImageData class to specify the ID of the external releationship.
    4. Add an external releationship to the main document part. Give the external
      releationship the same ID you specified in step 3.

    The following code just implements the steps described above. The image is added to the
    first paragraph in the word document.

    using (WordprocessingDocument newDoc = WordprocessingDocument.Open(@"c:\temp\external_img.docx", true))
    {
        var run = new Run();
    
        var picture = new Picture();
    
        var shape = new Shape() { Id = "_x0000_i1025", Style = "width:453.5pt;height:270.8pt" };
        var imageData = new ImageData() { RelationshipId = "rId56" };
    
        shape.Append(imageData);
    
        picture.Append(shape);
    
        run.Append(picture);
    
        var paragraph = newdoc.MainDocumentPart.Document.Body.Elements<Paragraph>().FirstOrDefault();
    
        paragraph.Append(run);      
    
        newDoc.MainDocumentPart.AddExternalRelationship(
           "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
           new System.Uri("<url to your picture>", System.UriKind.Absolute), "rId56");
    }
    

    In the code above I’ve omitted the code to define the shape type. I advise you to use a
    tool like the OpenXML SDK productivity tool
    to inspect a word document with an external releationship to an image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the Open XML SDK with C++/CLI with MSVC 10 compiler.
I'm trying to use an open-source project. Both the latest official (from a *.tar.gz
I am trying to open HTML file from the local URI which I use
I'm trying to use Nokogiri to grab some data from an XML file, then
I'm trying to read Stanford ecorner XML: open(http://ecorner.stanford.edu/RecentlyAdded.xml) but am running into the following
I been trying to find an Free/Open Source XML-FO processor that i could use
I'm trying to use URLLIB2 to open a URL and read back the contents
I am trying to use URLLoader to load an XML file from server (same
I am trying to use Python and LXML to create an XML file from
I am trying to use different open source apps in my project. Problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.