I'm developing a vsto-word addin and am inserting remote images into a word document in a picturecontentcontrol.
it all works fine, except on machines where the logged in user is connected to a remote login domain.
I get no information about the error. it just stops execution .. the image and an empty content control are inserted in the word document, but as two objects, so the contentcontrol is not taking it's image property. that's also the point where the code just stops executing:
public void resultImage(Result r, Dictionary<string, string> wizard)
{
if (this.hasSelection())
{
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(getCCRange(), this.getRandomControlName());
picture.LockContents = false;
toggleActiveCCs(false);
picture.Title = truncateCCTitle(r.title);
picture.Tag = getWizardString(wizard, r.arrange);
try {
Image img = Fetcher.getImage(r.data)
picture.Image = img;
}
catch (Exception e) {
Log.alert(e.Message);
}
afterInsert(picture.Range);
}
}
Right now, I use a temp file to store the image, as I was wondering if non-admin users may not have write permissions to memory ... I'm also using a temp file (with html) to insert a table, which works fine, also as limited domain-access user ... so I guess this should work for images too !?
I tried a bunch of stuff, including:
i asked this question also on MSDN
update X: i idenfified the error, which is hresult 0x80004005 (E_FAIL: Unspecified failure) that does not help a lot ... damn.
stacktrace:
Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName, Object& LinkToFile, Object& SaveWithDocument, Object& Range) at Microsoft.Office.Tools.Word.PictureContentControlImpl.SetImage(Image image) at Microsoft.Office.Tools.Word.PictureContentControlImpl.set_Image(Image value) at XXX.ThisAddIn.resultImage(Result r, Dictionary`2 wizard)
it's definitly a permission problem, how can I check/set proper permissions .. ?!!
I found a simple solution ... which works also on this domain-login machines .. just add an inlineshap to a range, and make the contentcontrol out of this range, like:
Word.Range rng = getCCRange();
string tempPath = Fetcher.getImage(r.data);
rng.InlineShapes.AddPicture(tempPath);
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(rng, this.getRandomControlName());