saifullah khan

saifullah khan

  • NA
  • 335
  • 295.2k

Parameter is not valid.

Oct 27 2011 6:14 AM
i have a ppt file which i have converted from ppt to image and then save it in db. it save successfully. then i retrieve it from db but it gives and error:
parameter is not valid
Image imag = Image.FromStream(stream);
 
here is the code for saving in db:
protected void Button1_Click(object sender, EventArgs e)
      {
            ApplicationClass pptApplication = new ApplicationClass();
            Presentation pptPresentation = pptApplication.Presentations.Open("saifullah.ppt", MsoTriState.msoFalse,
            MsoTriState.msoFalse, MsoTriState.msoFalse);
 
            var slides = new List<string>();
        
            for (var i = 1; i <= pptPresentation.Slides.Count; i++)
            {
                  string target = i+".jpeg".ToString();
              
               pptPresentation.Slides[i].Export(target, "jpg", width, height);
 
                  string pic = target;
              
              
              
         con.Open();
         cmd = new SqlCommand("insert into images values('"+@pic+"')",con);
         cmd.ExecuteNonQuery();
         con.Close();
                 
            }
 
            pptPresentation.Close();
}
 
and here is for retreiving from db.
 
MemoryStream stream = new MemoryStream();
            try
            {
                  con.Open();
                  cmd = new SqlCommand("select pics from images", con);
                  byte[] image = (byte[])cmd.ExecuteScalar();
 
                  stream.Write(image, 0, image.Length);
 
                  Image imag = Image.FromStream(stream);
                  Response.ContentType = "image/JPEG";
                  imag.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            finally
            {
                  con.Close();
                  stream.Close();
            }
 
please tell me what i need to correct

Answers (19)