Unable to add an Image to a powerpoint presentation using open xml -


i using following code add new slide ppt file , add image. using open xml 2.5 sdk.

a new slide getting added not image. there wrong in code?

int position = 1; using (presentationdocument presentationdocument = presentationdocument.open("c.pptx", true)) {    presentationpart presentationpart = presentationdocument.presentationpart;    slide slide = new slide(new commonslidedata(new shapetree()));    nonvisualgroupshapeproperties nonvisualproperties = slide.commonslidedata.shapetree.appendchild(new nonvisualgroupshapeproperties());   nonvisualproperties.nonvisualdrawingproperties = new nonvisualdrawingproperties() { id = 1, name = "" };   nonvisualproperties.nonvisualgroupshapedrawingproperties = new nonvisualgroupshapedrawingproperties();   nonvisualproperties.applicationnonvisualdrawingproperties = new applicationnonvisualdrawingproperties();    // specify group shape properties of new slide.   slide.commonslidedata.shapetree.appendchild(new groupshapeproperties());    // create slide part new slide.   slidepart slidepart = presentationpart.addnewpart<slidepart>();     // save new slide part.   slide.save(slidepart);   string imgid = "rid" + new random().next(2000).tostring();   imagepart imagepart = slidepart.addimagepart(imageparttype.png, imgid);     using (filestream stream = new filestream("a.png", filemode.open))   {     stream.position = 0;     imagepart.feeddata(stream);   }    slide.save(slidepart);    // modify slide id list in presentation part.   // slide id list should not null.   slideidlist slideidlist = presentationpart.presentation.slideidlist;    // find highest slide id in current list.   uint maxslideid = 1;   slideid prevslideid = null;    foreach (slideid slideid in slideidlist.childelements)   {     if (slideid.id > maxslideid)     {       maxslideid = slideid.id;     }      position--;     if (position == 0)     {       prevslideid = slideid;     }    }    maxslideid++;    // id of previous slide.   slidepart lastslidepart;    if (prevslideid != null)   {     lastslidepart = (slidepart)presentationpart.getpartbyid(prevslideid.relationshipid);   }   else   {     lastslidepart = (slidepart)presentationpart.getpartbyid(((slideid)(slideidlist.childelements[0])).relationshipid);   }     // use same slide layout of previous slide.   if (null != lastslidepart.slidelayoutpart)   {     slidepart.addpart(lastslidepart.slidelayoutpart);   }    // insert new slide slide list after previous slide.   slideid newslideid = slideidlist.insertafter(new slideid(), prevslideid);   newslideid.id = maxslideid;   newslideid.relationshipid = presentationpart.getidofpart(slidepart);    // save modified prsentation.   presentationpart.presentation.save(); 

thanks in advance.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -