Click here to Skip to main content
15,896,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi.

I have written the following code , and i want to retrive the inserted (in sql server2008) ImageContent and to display it instantly in a ImagePanel after uploading the picture , but i doesn't show the image.meanwhile the ImageContent insert command work properly.
so what shall i do to show the image?

C#
protected void Button1_Click(object sender, EventArgs e)
       {
           if (FileUpload.PostedFile != null && FileUpload.PostedFile.FileName != null)//Specify whether user has posted the file or not.
           {
               HttpPostedFile Picture = FileUpload.PostedFile;
               if (Picture.ContentLength==0) //Check the content of the file
               {
                   Response.Write("فایل شما هیچ محتوایی ندارد!");
                   return;
               }
               //check the path of the file that has to be valid form.
               if (Path.GetExtension(Picture.FileName).ToLower()!=".jpg" || Path.GetExtension(Picture.FileName).ToLower()!=".jpeg" || Path.GetExtension(Picture.FileName).ToLower()!=".jpe" ||Path.GetExtension(Picture.FileName).ToLower()!=".jfif")
               {
                   Response.Write("پسوند این فایل نامعتبر است!");
                   return;
               }
               //convert the picture into an array form to enable it for inserting into the database, and then read the file.
               byte[] MyImage = new Byte[Picture.ContentLength];
               Picture.InputStream.Read(MyImage, 0, Picture.ContentLength);

               //Insert into the UplaodPicture table by using StoredProcedure.
               SqlCommand Command = DataProvider.GenerateCommand("[dbo].[Insert_UploadPicture_SP]", CommandType.StoredProcedure);
               Command.Parameters.AddWithValue("@IdCode", GlobalVariables.IdCode);
               Command.Parameters.AddWithValue("@ImageContent", MyImage);
               Command.Parameters.AddWithValue("@ImageSize", Picture.ContentLength);
               Command.Parameters.AddWithValue("@ImageType", Picture.ContentType);

               try
               {
                   Command.Connection.Open();
                   Command.ExecuteNonQuery();
                   ImagePanel.ImageUrl = Picture.ToString();
                   Command.Connection.Close();
               }
               catch (Exception ex)
               {
                   EventLogger.Log(ex.Message, LogType.Error);
               }
               finally
               {
                   DataProvider.DisposeCommand(Command);
               }

           }
       }
Posted

1 solution

I think if you look closely, you will find that
C#
ImagePanel.ImageUrl = Picture.ToString();
Assigns the string "System.Web.HttpPostedFile" to the Image URL because it is not overridden and thus returns the name of the class rather than anything useful?

I suspect you want to load an image into the panel instead from the data you just downloaded...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900