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
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

VulpesRank #55 · 29.2K reputationPosted Oct 28, 2011, 1:21 AM EDT
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 27, 2011, 2:43 AM EDT
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 2:52 AM EDT
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 27, 2011, 3:00 AM EDT
try
{
con.Open();
cmd = new SqlCommand("select pics from images", con);
byte[] image = (byte[])cmd.ExecuteScalar();
stream.Write(image, 0, image.Length);
stream.Seek(0, SeekOrigin.Begin);
Image imag = Image.FromStream(stream);
Response.ContentType = "image/JPEG";
imag.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
con.Close();
stream.Close();
}
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 3:00 AM EDT
The problem this time is that you're writing a string to the database rather than the image itself.
I imagine that the Export() method will write to a disk file so I'd suggest you try:
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);
con.Open();
for (var i = 1; i <= pptPresentation.Slides.Count; i++)
{
string target = i.ToString() +".jpeg";
pptPresentation.Slides[i].Export(target, "jpg", width, height);
Image image = Image.FromFile(target);
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = ms.ToArray();
cmd = new SqlCommand("insert into images values(@picture)",con);
cmd.Parameters.Add("@picture", pic);
cmd.ExecuteNonQuery();
}
con.Close();
pptPresentation.Close();
}
The code for retrieving from the database should be exactly the same as what you finished up with in your previous thread.
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 3:36 AM EDT
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 3:39 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 5:05 AM EDT
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 5:31 AM EDT
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 5:34 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 5:43 AM EDT
You therefore need to replace 'target' with the full path to the file.
Another approach would be not to save the image itself to the database but just the path to it (as a string), but I'd see if you can get the present approach to work first.
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 6:32 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 6:40 AM EDT
In your other class, you then retrieve this byte array from the database and convert it back to an image.
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 8:17 AM EDT
con.Open();
cmd = new SqlCommand("select pics from images", con);
byte[] image = (byte[])cmd.ExecuteScalar(); stream.Write(image, 0, image.Length);
stream.Seek(0, SeekOrigin.Begin);
Image imag = Image.FromStream(stream);
Response.ContentType = "image/JPEG"; imag.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
could you please help me in this point?
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 27, 2011, 8:23 AM EDT
your 'deja vu' sense is correct and it is coming from here:
http://www.c-sharpcorner.com/Forums/Thread/145822/parameter-is-not-valid.aspx
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 9:09 AM EDT
saifullah khanRank #4,887 · 320 reputationPosted Oct 27, 2011, 9:17 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Oct 27, 2011, 9:40 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Oct 28, 2011, 11:10 AM EDT