can anyone tell me if this upload is correct ?http://forums.asp.net/t/1790845.aspx/1?can+anyone+tell+me+if+this+upload+is+correct+Mon, 09 Apr 2012 19:57:17 -040017908454923401http://forums.asp.net/p/1790845/4923401.aspx/1?can+anyone+tell+me+if+this+upload+is+correct+can anyone tell me if this upload is correct ? <p>i have followed this tuturial</p> <p><a href="http://geekswithblogs.net/dotNETvinz/archive/2009/08/02/uploading-and-storing-image-path-todatabase-and--image-to.aspx">http://geekswithblogs.net/dotNETvinz/archive/2009/08/02/uploading-and-storing-image-path-todatabase-and--image-to.aspx</a>&nbsp;</p> <p>in dault.cs part have i did this correctly ,seem to have alot od red underscores</p> <p>using System;<br> using System.Collections.Generic;<br> using System.Linq;<br> using System.Web;<br> using System.Web.UI;<br> using System.Web.UI.WebControls;</p> <p>public partial class Default : System.Web.UI.Page<br> {<br> &nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void StartUpLoad()<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the file name of the posted image<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string imgName = FileUpload1.FileName.ToString();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //sets the image path<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string imgPath = &quot;ImageStorage/&quot; &#43; imgName;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //then save it to the Folder<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileUpload1.SaveAs(Server.MapPath(imgPath));<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the size in bytes that<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgSize = FileUpload1.PostedFile.ContentLength; <br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //validates the posted file before saving<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpload1.PostedFile != null &amp;&amp; FileUpload1.PostedFile.FileName != &quot;&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpload1.PostedFile.ContentLength &gt; 5120) // 5120 KB means 5MB<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), &quot;Alert&quot;, &quot;alert('File is too big')&quot;, true);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //save the file<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Call the method to execute Insertion of data to the Database<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExecuteInsert(imgName, imgSize, imgPath);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(&quot;Save Successfully!&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;<br> &nbsp;&nbsp;&nbsp; private string GetConnectionString()<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //sets the connection string from your web config file. &quot;DBConnection&quot; is the name of your Connection String<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return System.Configuration.ConfigurationManager.ConnectionStrings[&quot;RegConnectionString&quot;].ConnectionString;<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;<br> &nbsp;&nbsp;&nbsp; private void ExecuteInsert(string name, int size, string path)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(GetConnectionString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES &quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#43; &quot; (@ImgName,@ImgSize,@ImgPath)&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlParameter[] param = new SqlParameter[3];<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[0] = new SqlParameter(&quot;@ImgName&quot;, SqlDbType.NVarChar, 50);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[1] = new SqlParameter(&quot;@ImgSize&quot;, SqlDbType.BigInt, 9999);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[2] = new SqlParameter(&quot;@ImgPath&quot;, SqlDbType.VarChar, 50);<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[0].Value = name;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[1].Value = size;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[2].Value = path;<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; param.Length; i&#43;&#43;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Parameters.Add(param[i]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.CommandType = CommandType.Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.ExecuteNonQuery();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (System.Data.SqlClient.SqlException ex)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string msg = &quot;Insert Error:&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg &#43;= ex.Message;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception(msg);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }</p> <p><br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; protected void Button1_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StartUpLoad();<br> &nbsp;&nbsp;&nbsp; }<br> }</p> 2012-04-09T16:57:07-04:004923405http://forums.asp.net/p/1790845/4923405.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>You put your&nbsp;<span>&nbsp;StartUpLoad() method inside your page load method which will not work, those need to be seperated.</span></p> 2012-04-09T16:58:55-04:004923416http://forums.asp.net/p/1790845/4923416.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>hi thanks justin can you show me how to seperate them just the tuturial doesnt show it</p> 2012-04-09T17:01:40-04:004923442http://forums.asp.net/p/1790845/4923442.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <pre class="prettyprint">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private void StartUpLoad() { //get the file name of the posted image string imgName = FileUpload1.FileName.ToString(); //sets the image path string imgPath = &quot;ImageStorage/&quot; &#43; imgName; //then save it to the Folder FileUpload1.SaveAs(Server.MapPath(imgPath)); //get the size in bytes that int imgSize = FileUpload1.PostedFile.ContentLength; //validates the posted file before saving if (FileUpload1.PostedFile != null &amp;&amp; FileUpload1.PostedFile.FileName != &quot;&quot;) { if (FileUpload1.PostedFile.ContentLength &gt; 5120) // 5120 KB means 5MB { Page.ClientScript.RegisterClientScriptBlock(typeof(Page), &quot;Alert&quot;, &quot;alert('File is too big')&quot;, true); } else { //save the file //Call the method to execute Insertion of data to the Database ExecuteInsert(imgName, imgSize, imgPath); Response.Write(&quot;Save Successfully!&quot;); } } } private string GetConnectionString() { //sets the connection string from your web config file. &quot;DBConnection&quot; is the name of your Connection String return System.Configuration.ConfigurationManager.ConnectionStrings[&quot;RegConnectionString&quot;].ConnectionString; } private void ExecuteInsert(string name, int size, string path) { SqlConnection conn = new SqlConnection(GetConnectionString()); string sql = &quot;INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES &quot; &#43; &quot; (@ImgName,@ImgSize,@ImgPath)&quot;; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter(&quot;@ImgName&quot;, SqlDbType.NVarChar, 50); param[1] = new SqlParameter(&quot;@ImgSize&quot;, SqlDbType.BigInt, 9999); param[2] = new SqlParameter(&quot;@ImgPath&quot;, SqlDbType.VarChar, 50); param[0].Value = name; param[1].Value = size; param[2].Value = path; for (int i = 0; i &lt; param.Length; i&#43;&#43;) { cmd.Parameters.Add(param[i]); } cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = &quot;Insert Error:&quot;; msg &#43;= ex.Message; throw new Exception(msg); } finally { conn.Close(); } } protected void Button1_Click(object sender, EventArgs e) { StartUpLoad(); } }</pre> <p></p> 2012-04-09T17:18:31-04:004923457http://forums.asp.net/p/1790845/4923457.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>thanks justin no errors there , but i have red underscores under the name <span size="2" face="Consolas" style="font-family:Consolas; font-size:small"> <span size="2" face="Consolas" style="font-family:Consolas; font-size:small"><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"></span></span></span></p> <p>FileUpload1 how can i solve that?</p> <p><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"></span></span></p> 2012-04-09T17:30:55-04:004923490http://forums.asp.net/p/1790845/4923490.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>Make sure you have a file upload object on your asp page, from the link you posted you should have.</p> <p><span>&lt;</span><span>asp</span><span>:</span><span>FileUpload</span><span>&nbsp;</span><span>ID</span><span>=&quot;FileUpload1&quot;</span><span>&nbsp;</span><span>runat</span><span>=&quot;server&quot;</span><span>&nbsp;</span><span>/&gt;</span></p> 2012-04-09T17:54:01-04:004923495http://forums.asp.net/p/1790845/4923495.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>see here what r u missing.</p> <p>http://aspalliance.com/150_how_to_upload_files_in_asp_net</p> 2012-04-09T17:58:41-04:004923512http://forums.asp.net/p/1790845/4923512.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>yip justin i have that in my souce code</p> <p>&lt;<span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small"><span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small"><span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small">asp</span></span></span><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small">:</span></span></span><span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small"><span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small"><span size="2" face="Consolas" color="#800000" style="font-family:Consolas; color:#800000; font-size:small">FileUpload</span></span></span><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"> </span></span><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small"><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small"><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small">ID</span></span></span><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small">=&quot;FileUpload1&quot;</span></span></span><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"> </span></span><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small"><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small"><span size="2" face="Consolas" color="#ff0000" style="font-family:Consolas; color:#ff0000; font-size:small">runat</span></span></span><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small">=&quot;server&quot;</span></span></span><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"><span size="2" face="Consolas" style="font-family:Consolas; font-size:small"> </span></span><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small">/&gt;</span></p> <p></p> <p><span size="2" face="Consolas" color="#0000ff" style="font-family:Consolas; color:#0000ff; font-size:small"></span></p> 2012-04-09T18:10:48-04:004923520http://forums.asp.net/p/1790845/4923520.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>thanks evello but that tuturial you gave me is vb im using c# webforms</p> 2012-04-09T18:17:16-04:004923632http://forums.asp.net/p/1790845/4923632.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>If you have it i see no reason for it to be giving you an error., When you try to run it what does it do/say?</p> 2012-04-09T19:28:18-04:004923634http://forums.asp.net/p/1790845/4923634.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>hi justin it gives me this code on line 25</p> <p>Line 23:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string imgPath = &quot;ImageStorage/&quot; &#43; imgName;<br> Line 24:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //then save it to the Folder <br> Line 25:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileUpload1.SaveAs(Server.MapPath(imgPath));<br> Line 26: <br> Line 27:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the size in bytes that</p> 2012-04-09T19:30:55-04:004923640http://forums.asp.net/p/1790845/4923640.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>Can you post your source code for both the aspx file and the aspx.cs file so i can take a quick look, I think i might know what it is just need to see both sides to make sure.</p> 2012-04-09T19:35:08-04:004923653http://forums.asp.net/p/1790845/4923653.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>this is the default2.aspx source</p> <p>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default2.aspx.cs&quot; Inherits=&quot;Default2&quot; %&gt;</p> <p>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&quot;&gt;</p> <p>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&quot;&gt;<br> &lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;title&gt;Untitled Page&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &nbsp;&nbsp;&nbsp; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;div&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:FileUpload ID=&quot;FileUpload1&quot; runat=&quot;server&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Save&quot; onclick=&quot;Button1_Click&quot; /&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/form&gt;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> <p>this is the default2.aspx.cs</p> <p>using System;<br> using System.Collections.Generic;<br> using System.Linq;<br> using System.Web;<br> using System.Web.UI;<br> using System.Web.UI.WebControls;<br> using System.Data.SqlClient;<br> using System.Data;</p> <p><br> public partial class Default2 : System.Web.UI.Page<br> {<br> &nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; private void StartUpLoad()<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the file name of the posted image <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string imgName = FileUpload1.FileName.ToString();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //sets the image path <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string imgPath = &quot;ImageStorage/&quot; &#43; imgName;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //then save it to the Folder <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileUpload1.SaveAs(Server.MapPath(imgPath));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //get the size in bytes that <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int imgSize = FileUpload1.PostedFile.ContentLength;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //validates the posted file before saving <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpload1.PostedFile != null &amp;&amp; FileUpload1.PostedFile.FileName != &quot;&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpload1.PostedFile.ContentLength &gt; 5120) // 5120 KB means 5MB <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), &quot;Alert&quot;, &quot;alert('File is too big')&quot;, true);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //save the file <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Call the method to execute Insertion of data to the Database <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExecuteInsert(imgName, imgSize, imgPath);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(&quot;Save Successfully!&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; private string GetConnectionString()<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //sets the connection string from your web config file. &quot;DBConnection&quot; is the name of your Connection String <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return System.Configuration.ConfigurationManager.ConnectionStrings[&quot;RegConnectionString&quot;].ConnectionString;<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; private void ExecuteInsert(string name, int size, string path)<br> &nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(GetConnectionString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES &quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#43; &quot; (@ImgName,@ImgSize,@ImgPath)&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlParameter[] param = new SqlParameter[3];</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[0] = new SqlParameter(&quot;@ImgName&quot;, SqlDbType.NVarChar, 50);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[1] = new SqlParameter(&quot;@ImgSize&quot;, SqlDbType.BigInt, 9999);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[2] = new SqlParameter(&quot;@ImgPath&quot;, SqlDbType.VarChar, 50);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[0].Value = name;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[1].Value = size;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param[2].Value = path;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; param.Length; i&#43;&#43;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Parameters.Add(param[i]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.CommandType = CommandType.Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.ExecuteNonQuery();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (System.Data.SqlClient.SqlException ex)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string msg = &quot;Insert Error:&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg &#43;= ex.Message;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception(msg);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; protected void Button1_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StartUpLoad();<br> &nbsp;&nbsp;&nbsp; }<br> }</p> 2012-04-09T19:42:16-04:004923668http://forums.asp.net/p/1790845/4923668.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>Have you created the&nbsp;ImageStorage folder?&nbsp;</p> 2012-04-09T19:49:18-04:004923675http://forums.asp.net/p/1790845/4923675.aspx/1?Re+can+anyone+tell+me+if+this+upload+is+correct+Re: can anyone tell me if this upload is correct ? <p>i did but i created it like this Image_Storage rather than ImageStorage your spot on thankyou now fixed</p> <p>see it says saved succefully , but doesnt show on the profile of any user?</p> 2012-04-09T19:57:17-04:00