2

Hie guys,

I have a block of code here:

System.Net.WebClient wc = new System.Net.WebClient();
byte[] data = wc.DownloadData(xmlTempNode.Attributes["imageurl"].Value.ToString());
MemoryStream ms = new MemoryStream(data);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
string strImagePath = pptdirectoryPath + "\\" + currentSlide + "_" + shape.Id + ".png";
img.Save(strImagePath);
tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));
shape.Delete();

tempSlide.Shapes.AddPicture works fine for smaller images,and it fails when resolution is higher(here fail means response is not received for infinite time and throws exception when page is refreshed).

Exception Message: The remote procedure call failed. (Exception from HRESULT: 0x800706BE) at Microsoft.Office.Interop.PowerPoint.Shapes.AddPicture(String FileName, MsoTriState LinkToFile, MsoTriState SaveWithDocument, Single Left, Single Top, Single Width, Single Height).

Any help would be appreciated.

Charles
  • 50,943
  • 13
  • 104
  • 142
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • I am also having trouble with this issue. I would like to know what your tempSlide object is? the AddPicture function seems to be adding the image to different locations on the page depending on the slide template. My tempslide object is `PowerPoint.Application ppApp = Globals.ThisAddIn.Application; PowerPoint.SlideRange tempSlide = ppApp.ActiveWindow.Selection.SlideRange;` – JKennedy Sep 18 '14 at 10:42
  • @user1: can you share how are you using the method?? – Milind Anantwar Sep 22 '14 at 06:16

1 Answers1

3

Finally i solved the issue.used below code to addpicture

tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Convert.ToInt32(shape.Left), Convert.ToInt32(shape.Top), Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));//load new image to shape

The problem was, i was sending msoFalse for LinkToFile and msoTrue for SaveWithDocument.

and now ,passing msoTrue for LinkToFile and msoFalse for SaveWithDocument did my job.

happy Coding..

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125