Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Image is not attached from database with AsyncFileUpload control in asp.net?
    primarykey
    data
    text
    <p>I am working with ajax AsyncFileUpload control. I have requirement where when user click on fileuploader and select the file from picture and immediately the picture will display on my image control I am using the following method </p> <pre><code> protected void fileUploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { string imagepath = Server.MapPath("~/Pics/"); string serverfilename = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName); string fullpath = Path.Combine(imagepath, serverfilename); string path = "~/Pics/" + serverfilename; //string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName); //string path = Server.MapPath("~/Pics/") + filename; AsyncFileUpload1.SaveAs(fullpath); // FileUpload1.PostedFile.SaveAs(path); SqlCommand cmd = new SqlCommand("insert findfriend values('" + path + "','" + TextBox1.Text + "')", con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); SqlCommand GetImage = new SqlCommand("select * from findfriend where name='" + TextBox1.Text + "'", con); GetImage.CommandType = CommandType.Text; SqlDataReader dr = GetImage.ExecuteReader(); dr.Read(); if (dr.HasRows) { Image1.ImageUrl = dr["picture"].ToString(); } } </code></pre> <p>My aspx source </p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; // This function will execute after file uploaded successfully function uploadComplete() { document.getElementById('&lt;%=lblMsg.ClientID %&gt;').innerHTML = "File Uploaded Successfully"; } // This function will execute if file upload fails function uploadError() { document.getElementById('&lt;%=lblMsg.ClientID %&gt;').innerHTML = "File upload Failed."; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;ajax:ToolkitScriptManager ID="scriptManager1" runat="server"/&gt; Your Name:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;asp:TextBox ID="TextBox1" runat="server" Width="223px"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;br /&gt; Upload Picture:&lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt; &lt;br /&gt; &lt;ajax:AsyncFileUpload ID="AsyncFileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError" CompleteBackColor="White" Width="350px" runat="server" UploaderStyle="Modern" UploadingBackColor="#CCFFFF" ThrobberID="imgLoad" OnUploadedComplete="fileUploadComplete" /&gt; &lt;asp:Label ID="lblMsg" runat="server" Text="Label"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Image ID="Image1" runat="server" Height="295px" Width="338px" /&gt; &lt;br /&gt; &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload" /&gt; &amp;nbsp;&lt;asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" /&gt; &lt;br /&gt; &lt;asp:Label ID="Label1" runat="server"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now the problem is this that my picture path is saving into database succesfully image is not binding with image control Experts tell me please where i am wrong</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload