is there an aspose method that i can use to copy the complete slide notes pictures and everything about a slide from one ppt to a new one, using c#
Hi,
Yes, you should see this example code.
hi thanks for that
one question, im trying to add multiple slides but for some reason its not adding them my code is this
protected void Page_Load(object sender, EventArgs e)
{
Session["style"] = "design1.ppt";
Presentation dstPres = new Presentation(@Server.MapPath("")+"\\creationtest.ppt");
try
{
string[] selectedPPTs = Session["selectedSlides"] as string[];
string sqlIn = "";
if (0 != selectedPPTs.Length)
{
for (int x = 0; x < selectedPPTs.Length; x++)
{
sqlIn += selectedPPTs[x] + ",";
Response.Write("file id = " + selectedPPTs[x] + "
");
}
sqlIn = sqlIn.Substring(0, sqlIn.Length - 1);
try
{
//con = new SqlConnection(ConfigurationSettings.AppSettings["asposeslideDbConn"]);
con = new SqlConnection("Data Source=192.168.50.10;Initial Catalog=asposeslidetest;Persist Security Info=True;User ID=ih;Password=A1");
cmd = new SqlCommand("sp_get_selected_slides", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
objParam1 = cmd.Parameters.Add("@inclaus", SqlDbType.NVarChar);
objParam1.Direction = ParameterDirection.Input;
objParam1.Value = sqlIn;
if (con.State.Equals(ConnectionState.Closed))
{
con.Open();
SqlDataReader srdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (null != Session["style"])
{
}
while (srdr.Read())
{
Presentation srcPrs = new Presentation(@Server.MapPath("")+"\\uploaded_ppts\\"+srdr[2]);
CloneSlideWithNotes(srcPrs, Convert.ToInt32(srdr[1]), dstPres);
}
}
}
catch (Exception dbQueryEx)
{
Response.Write("problem with query on line 74 " + dbQueryEx.Message + "sql in = " + sqlIn);
}
}
}
catch (Exception pgLoadEx)
{
Response.Write("prolem exception fired on line 80"+ pgLoadEx.Message);
}
}
protected void CloneSlideWithNotes(Presentation srcPres, int srcSlidePosition, Presentation dstPres)
{
try
{
Slide srcSld;
srcSld = srcPres.GetSlideByPosition(srcSlidePosition);
if (srcSld == null)
return;
int dstSldPosition;
dstSldPosition = dstPres.Slides.LastSlidePosition + 1;
//Clone slide now, we have all the necessary parameters
Slide dstSld;
dstSld = srcPres.CloneSlide(srcSld, dstSldPosition, dstPres, new SortedList());
//Now below is the code to copy srcSld notes to dstSld notes
//Add notes to dstSld and clear all paragraphs
dstSld.AddNotes();
dstSld.Notes.Paragraphs.Clear();
//Finally add all the pargraphs in notes of sldSrc into the notes of dstSld
foreach (Paragraph srcPara in srcSld.Notes.Paragraphs)
{
//Create the replica of srcPara
Paragraph dstPara = new Paragraph(srcPara);
//Add this Replica to dstSld.Notes.Paragraphs
dstSld.Notes.Paragraphs.Add(dstPara);
}
}
catch (Exception CloneSlideEx)
{
Response.Write("error in cloneslide method " + CloneSlideEx.Message);
}
}
thanks
andrew
Make sure you are passing valid parameter value of srcSlidePosition in **CloneSlideWithNotes()
Because if there is no slide at position srcSlidePosition in srcPres, then, srcSld will be null and method will return without doing anything, see the code below
Slide srcSld;
srcSld = srcPres.GetSlideByPosition(srcSlidePosition);
if (srcSld == null) //if it is null, it will not do any thing and return
return;
Hi Shakeel
I now have it working to a certain degree, however for some reason when i add the notes its putting them on the a new slide.
here is my code
try
{
Presentation clonePres = new Presentation(@Server.MapPath("") + "\\uploaded_ppts\\" + srcPres);
Slide srcSld;
srcSld = clonePres.GetSlideByPosition(srcSlidePosition);
if (srcSld == null)
return;
int dstSldPosition;
dstSldPosition = dstPres.Slides.LastSlidePosition + 1;
Slide dstSld = dstPres.AddEmptySlide();
clonePres.CloneSlide(srcSld, dstSldPosition, dstPres, new SortedList());
dstSld.AddNotes();
dstSld.Notes.Paragraphs.Clear();
//add all the pargraphs in notes of sldSrc into the notes of dstSld
foreach (Paragraph srcPara in srcSld.Notes.Paragraphs)
{
Paragraph dstPara = new Paragraph(srcPara);
dstSld.Notes.Paragraphs.Add(dstPara);
}
}
catch (Exception CloneSlideEx)
{
Response.Write("error in cloneslide method " + CloneSlideEx.Message);
}
thanks in advance
andrew
Please update your code like this.
int dstSldPosition;
dstSldPosition = dstPres.Slides.LastSlidePosition + 1;
//Your commented line
//Slide dstSld = dstPres.AddEmptySlide();
clonePres.CloneSlide(srcSld, dstSldPosition, dstPres, new SortedList());
//The line added by me
dstSld = dstPres.GetSlideByPosition(dstSldPosition);
dstSld.AddNotes();
great thanks seems to work now
one small thing though i added
Slide dstSld;
dstSld = dstPres.GetSlideByPosition(dstSldPosition);
andrew
can you tell me what would cause this error
The process cannot access the file 'C:\Inetpub\wwwroot\apose2\creationtest2.ppt' because it is being used by another process
thanks
andrew
Hello Andrew,
Such an exception occurs, when you try to read/write the file, which is being written by some other process.
In your case, I think, you are reading creationtest2.ppt and then writing it back and while doing so, you created another process that tried to read it while it was being written by the previous process.
If you want to send the output file to user on the web, then you can simply use this code snippet
Response.Clear();
Response.ContentType = "application/vnd.ms-powerpoint";
Response.AppendHeader("Content-Disposition", "attachment; filename=demo.ppt");
Response.Flush();
// Send the file
System.IO.Stream st = this.Response.OutputStream;
pres.Write(st);
Response.End();