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
VulpesPosted Oct 28, 2011, 5:21 AM
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx
Suthish NairPosted Oct 28, 2011, 3:10 PM
Suthish NairPosted Oct 27, 2011, 1:40 PM
saifullah khanPosted Oct 27, 2011, 1:17 PM
VulpesPosted Oct 27, 2011, 1:09 PM
Javeed M ShaikhPosted Oct 27, 2011, 12:23 PM
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
saifullah khanPosted Oct 27, 2011, 12:17 PM
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?
VulpesPosted Oct 27, 2011, 10:40 AM
In your other class, you then retrieve this byte array from the database and convert it back to an image.
saifullah khanPosted Oct 27, 2011, 10:32 AM
VulpesPosted Oct 27, 2011, 9:43 AM
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 khanPosted Oct 27, 2011, 9:34 AM
saifullah khanPosted Oct 27, 2011, 9:31 AM
VulpesPosted Oct 27, 2011, 9:05 AM
saifullah khanPosted Oct 27, 2011, 7:39 AM
saifullah khanPosted Oct 27, 2011, 7:36 AM
VulpesPosted Oct 27, 2011, 7:00 AM
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.
Prabhu RajaPosted Oct 27, 2011, 7:00 AM
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();
}
saifullah khanPosted Oct 27, 2011, 6:52 AM
Prabhu RajaPosted Oct 27, 2011, 6:43 AM