Hi im trying to create a thumbnail of each slide and at the same time store the notes in a db. however, the notes seem to be out of sinc with the picture, eg thumbnail 5 has the notes for will have the notes for slide 7.
my code is below
protected void upload_ppt_Click(object sender, EventArgs e)
{
string fn = Path.GetFileName(FileUpload.PostedFile.FileName);
fn = System.Text.RegularExpressions.Regex.Replace(fn, "'", "''");
string[] fileNameSplit = fn.Split(new Char [] {'.'});
if (null != FileUpload.PostedFile)
{
try
{
//sp_insertnewpresentation
//con = new SqlConnection(ConfigurationSettings.AppSettings["asposeslideDbConn"]);
con = new SqlConnection("Data Source=localhost;Initial Catalog=asposeslidetest;Persist Security Info=True;User ID=user;Password=pass");
cmd = new SqlCommand("sp_insertnewpresentation", con);
//msg.Text += "connection string = " + ConfigurationSettings.AppSettings["asposeslideDbConn"].ToString() + "\n";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
objParam1 = cmd.Parameters.Add("@filename", SqlDbType.VarChar);
//returnParam = cmd.Parameters.Add("@returnValue", SqlDbType.Int);
objParam1.Direction = ParameterDirection.Input;
//returnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = fn;
//objParam2.Value = txtPass;
try
{
string pptId = "";
if (con.State.Equals(ConnectionState.Closed))
{
con.Open();
SqlDataReader srdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (srdr.Read())
{
pptId = srdr[0].ToString();
FileUpload.PostedFile.SaveAs(Server.MapPath("") + "\\uploaded_ppts\\" + pptId +"."+ fileNameSplit[fileNameSplit.Length - 1].ToString());
}
}
con.Close();
Presentation pres = new Presentation(Server.MapPath("") + "\\uploaded_ppts\\" + pptId + "." + fileNameSplit[fileNameSplit.Length - 1].ToString());
IEnumerator slides = pres.Slides.GetEnumerator();
int j = 1;
while (slides.MoveNext())
{
Slide slide = (Slide)slides.Current;
//slideTxt = slide.Notes(j);
System.Drawing.Image image = slide.GetThumbnail(new Size(250, 187));
image.Save(Server.MapPath("")+"\\upload_ppt_images\\"+pptId+"_"+j + ".jpg");
//Slide sld = pres1.GetSlideByPosition(6);
Paragraphs paraNotes = slide.Notes.Paragraphs;
string paraText = "";
foreach (Paragraph para in paraNotes)
{
paraText += "
";
foreach (Portion port in para.Portions)
{
paraText += port.Text;
}
paraText += "
";}
//sp_ins_presentation_cont
con = new SqlConnection("Data Source=localhost;Initial Catalog=asposeslidetest;Persist Security Info=True;User ID=user;Password=pass");
cmd = new SqlCommand("sp_ins_presentation_cont", con);
//msg.Text += "connection string = " + ConfigurationSettings.AppSettings["asposeslideDbConn"].ToString() + "\n";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter insertParam1;
SqlParameter insertParam2;
SqlParameter insertParam3;
SqlParameter insertParam4;
insertParam1 = cmd.Parameters.Add("@slide_id", SqlDbType.Int);
insertParam2 = cmd.Parameters.Add("@slide_number", SqlDbType.Int);
insertParam3 = cmd.Parameters.Add("@slide_image", SqlDbType.VarChar);
insertParam4 = cmd.Parameters.Add("@slide_text", SqlDbType.Text);
insertParam1.Direction = ParameterDirection.Input;
insertParam2.Direction = ParameterDirection.Input;
insertParam3.Direction = ParameterDirection.Input;
insertParam4.Direction = ParameterDirection.Input;
insertParam1.Value = pptId;
insertParam2.Value = j;
insertParam3.Value = pptId + "_" + j + ".jpg";
insertParam4.Value = paraText;
//objParam2.Value = txtPass;
try
{
//string pptId = "";
if (con.State.Equals(ConnectionState.Closed))
{
con.Open();
//SqlDataReader srdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.ExecuteNonQuery();
}
con.Close();
}
catch (Exception InsertEx)
{
msg.Text += "error on line 133 "+ InsertEx.Message;
}
j++;
}
msg.Text += "file successfully uploaded";
}
catch (Exception q_Error)
{
msg.Text += "error line 62 " + q_Error.Message;
}
}
catch (Exception f_Error)
{
msg.Text += "error line 68 " + f_Error.Message;
}
}