ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Set (Assign) value to FileUpload control using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="itsme"> itsme</a>,</p> <p>You need to show your data of file in lable when you are going to update that time need to check whether label is empty or not accordingly to label existing data will insert else data will not insert. Refer below code i make some changes in your code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;div style=&#34;scrollbar-highlight-color: aqua&#34; onscroll=&#34;true&#34;&gt; &lt;table align=&#34;center&#34; style=&#34;position: relative; top: 20px; margin-left: 35%; border-style: double; align-content: center&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;table align=&#34;center&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Job Seeker Name&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;jsname&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Address:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_add&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Phone no.:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_no&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Email:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_email&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;10th Marks(CGPA):&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_tenth&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;12th Marks(CGPA:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_twelve&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Graduation Marks(CGPA):&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txt_graduate&#34; runat=&#34;server&#34; MaxLength=&#34;200&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Qualification:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:DropDownList ID=&#34;txt_quali&#34; runat=&#34;server&#34; class=&#34;form-control input-lg&#34;&gt; &lt;asp:ListItem&gt;--Select Qualification--&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;10th&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;12th&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Graduate&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Masters&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Phd&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Upload Resume:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:FileUpload ID=&#34;FileUpload1&#34; runat=&#34;server&#34; /&gt; &lt;asp:Label ID=&#34;fname&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt; &lt;asp:Button ID=&#34;btnsave&#34; runat=&#34;server&#34; Text=&#34;Save&#34; OnClick=&#34;btnsave_Click&#34; CssClass=&#34;btn btn-info&#34; /&gt; &lt;asp:Button ID=&#34;btnUpdate&#34; runat=&#34;server&#34; Text=&#34;Update&#34; OnClick=&#34;btnUpdate_Click&#34; CssClass=&#34;btn btn-info&#34; Visible=&#34;false&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;tr&gt; &lt;td align=&#34;center&#34;&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;lblMessage&#34; runat=&#34;server&#34; EnableViewState=&#34;false&#34; ForeColor=&#34;Blue&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type=&#34;hidden&#34; runat=&#34;server&#34; id=&#34;Id&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; using System.Configuration; using System.IO; using System.Data;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">SqlConnection mycon = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ToString()); SqlCommand cmd = new SqlCommand(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { mycon.Open(); cmd.Connection = mycon; cmd.CommandType = CommandType.Text; cmd.CommandText = &#34;Select Name,email from Common_regn2 where email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { jsname.Text = dr[&#34;Name&#34;].ToString(); jsname.ReadOnly = true; txt_email.Text = dr[&#34;email&#34;].ToString(); txt_email.ReadOnly = true; } } Session[&#34;name&#34;] = jsname.Text.ToString(); } if (!IsPostBack) { mycon.Close(); mycon.Open(); cmd.Connection = mycon; cmd.CommandType = CommandType.Text; cmd.CommandText = &#34;Select js_address,Contact,tenth,twelve,graduate,Qualification from Job_Seeker_Profile where email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { txt_quali.SelectedValue = dr[&#34;Qualification&#34;].ToString(); txt_add.Text = dr[&#34;js_address&#34;].ToString(); txt_no.Text = dr[&#34;Contact&#34;].ToString(); txt_tenth.Text = dr[&#34;tenth&#34;].ToString(); txt_twelve.Text = dr[&#34;twelve&#34;].ToString(); txt_graduate.Text = dr[&#34;graduate&#34;].ToString(); fname.Text = dr[&#34;file&#34;].ToString(); btnsave.Visible = false; btnUpdate.Visible = true; } } } } protected void btnsave_Click(object sender, EventArgs e) { string filename = Path.GetFileName(FileUpload1.PostedFile.FileName); string contentType = FileUpload1.PostedFile.ContentType; using (Stream fs = FileUpload1.PostedFile.InputStream) { using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); string constr = ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string query = &#34;Insert into Job_Seeker_Profile (js_name,js_address,Contact,email,tenth,twelve,graduate,resumefile,Qualification) Values (@Name,@Address,@Contact,@email,@tenth,@twelve,@graduate,@file,@Qualification)&#34;; using (SqlCommand cmd = new SqlCommand(query)) { cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id.Value); cmd.Parameters.AddWithValue(&#34;@Name&#34;, jsname.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@Address&#34;, txt_add.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@Contact&#34;, txt_no.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@email&#34;, txt_email.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@tenth&#34;, txt_tenth.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@twelve&#34;, txt_twelve.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@graduate&#34;, txt_graduate.Text.Trim().ToString()); cmd.Parameters.AddWithValue(&#34;@file&#34;, bytes); cmd.Parameters.AddWithValue(&#34;@Qualification&#34;, txt_quali.Text.Trim().ToString()); con.Open(); cmd.ExecuteNonQuery(); con.Close(); lblMessage.Text = &#34;Saved Successfully.&#34;; } } } } Response.Redirect(Request.Url.AbsoluteUri); } protected void btnUpdate_Click(object sender, EventArgs e) { string filename = Path.GetFileName(FileUpload1.PostedFile.FileName); string contentType = FileUpload1.PostedFile.ContentType; using (Stream fs = FileUpload1.PostedFile.InputStream) { using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); string constr = ConfigurationManager.ConnectionStrings[&#34;Q_SS_regnConnectionString1&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string query = &#34;UPDATE Job_Seeker_Profile SET js_name=@Name,js_address=@Address,Contact=@Contact,email=@email,tenth=@tenth,twelve=@twelve,graduate=@graduate,resumefile=@file,Qualification=@Qualification WHERE email=&#39;&#34; + Session[&#34;mail&#34;].ToString() + &#34;&#39;&#34;; using (SqlCommand cmd = new SqlCommand(query)) { if (string.IsNullOrEmpty(fname.Text)) { cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Id&#34;, Id.Value); cmd.Parameters.AddWithValue(&#34;@Name&#34;, jsname.Text); cmd.Parameters.AddWithValue(&#34;@Address&#34;, txt_add.Text); cmd.Parameters.AddWithValue(&#34;@Contact&#34;, txt_no.Text); cmd.Parameters.AddWithValue(&#34;@email&#34;, txt_email.Text); cmd.Parameters.AddWithValue(&#34;@tenth&#34;, txt_tenth.Text); cmd.Parameters.AddWithValue(&#34;@twelve&#34;, txt_twelve.Text); cmd.Parameters.AddWithValue(&#34;@graduate&#34;, txt_graduate.Text); cmd.Parameters.AddWithValue(&#34;@file&#34;, bytes); cmd.Parameters.AddWithValue(&#34;@Qualification&#34;, txt_quali.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); lblMessage.Text = &#34;Updated Successfully.&#34;; } else { lblMessage.Text = &#34;Already exist data.&#34;; } } } } } Response.Redirect(Request.Url.AbsoluteUri); }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/951654/Set-Assign-value-to-FileUpload-control-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/951654/Set-Assign-value-to-FileUpload-control-using-C-and-VBNet-in-ASPNet/Wed, 07 Aug 2019 01:04:08 GMT