none
Inserting Picture (from Web- through Webdav) to Word document using VSTO code RRS feed

  • Question

  • Hi,

    I have been trying to insert an image/picture to current selection in word. with help of code -

    Microsoft.Office.Interop.Word.InlineShape s =  this.Application.Selection.InlineShapes.AddPicture(
                   @"http://127.0.0.1:9001/test/myimage.png", true, true, Type.Missing);

    This code works fine if image is on desktop or network shared location but some issues for URL exposed through Webdav.

    On inserting the picture word shows - "The linked image cannot be displayed....." message. If we close and open word document again then image appears properly.

    Some observations:

    1. If we use same option through Ribbon  "Insert -> Picture -> Enter path and click on "Link to File" then we get Prompt for Wevdav password (Only once, later Word caches it) and linked images appear properly.

    2. Updating the shape explicitly wouldnt help. 

    s.LinkFormat.Update();

    What we are looking for is, Does Ribbon "Insert" functionality do something additional to prompt Webdav authentication to cache? if we want to achieve the same? what needs to be invoked before we make call to AddPicture API?

    Thanks

    H


    Thursday, March 19, 2015 11:40 AM

All replies

  • VSTO doesn't provide anything for that. I'd recommend asking Word specific questions on the Word for Developers forum instead.
    Thursday, March 19, 2015 2:14 PM
  • would you please comment on this question - https://social.msdn.microsoft.com/Forums/vstudio/en-US/c8441acf-48e0-468d-b728-68639159dbb0/inserting-picture-from-web-through-webdav-to-word-document-using-vsto-code?forum=vsto

    we have been told that this forum is appropriate to get the correct answer on this.

    Thanks

    H

    • Merged by L.HlModerator Monday, March 23, 2015 6:43 AM duplicated
    Friday, March 20, 2015 5:57 AM
  • Hi,

    >> On inserting the picture word shows - "The linked image cannot be displayed....." message. If we close and open word document again then image appears properly.

    Do you need to input password when you open that file?

    Could you share an image link of Webdav?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 20, 2015 9:51 AM
    Moderator
  • Thanks for the response.. 

    No, when document is opened again, then you dont need to enter the password. 

    Somehow on document open event MS word knows how to retreive password from cookie for given domain.

    When you insert the image using ribbon -> insert picture option, 
    MS Word first looks into cache if the domain cokkie already available then bypass authentication/password prompt

    Otherwise it would show the prompt and store the cookie in cache again.

    The mystry is how MS-Word interacts with this "cached cookies"

    while doing more reading on this, it seems MS Word has been using Klink.dll for this kind of functionality https://support.microsoft.com/en-us/kb/899927 but it would be great if you can provide more pointers.

    >>Could you share an image link of Webdav?

    Since, it's my local webdav server, you would not be able to access the image link, may be you can upload an image to sharepoint (as sharepoint also supports webdav) and use that for reproducing this problem at your end.

    Thanks

    H

    Friday, March 20, 2015 11:03 AM
  • Hi,

    The account data may cached in the browser’s cookie. Please clear browser’s cookie and open the document again to check whether it opens the prompt for authentication.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 23, 2015 6:31 AM
    Moderator
  • The problem here is not prompt. (even if do that, as we are trying to acheive this programatically, we cannot keep clearing browser cache, it's not feasible)

    We want to achieve same what Microsoft Ribbon 'Insert Picture' functionality does.

    If the data is already present in cookie (As per your logic) shouldnt word use that and show the image in MS-Word?

    Do we need to do anything additional to make MS-Word to read these cookies? 

    Monday, March 23, 2015 7:57 AM
  • Hi,

    Through the UI, it can have the prompt for authentication, through program way, it doesn’t open the prompt.

    In my opinion, the word object model doesn’t provide a way to cache the authentication data.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 25, 2015 7:54 AM
    Moderator