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.Save AjaxFileUpload file in folder and path in Database in ASP.Net<p>Hi <a class="username" rel="eswardatta"> eswardatta</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:ToolkitScriptManager runat=&#34;server&#34;&gt; &lt;/asp:ToolkitScriptManager&gt; &lt;asp:AjaxFileUpload ID=&#34;AjaxFileUpload11&#34; runat=&#34;server&#34; MaximumNumberOfFiles=&#34;5&#34; Width=&#34;400px&#34; OnUploadComplete=&#34;OnUploadComplete&#34; /&gt; &lt;asp:GridView ID=&#34;gvImages&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Image Id&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:ImageField DataImageUrlField=&#34;Path&#34; HeaderText=&#34;Image&#34; ControlStyle-Width=&#34;50px&#34; ControlStyle-Height=&#34;50px&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO; using AjaxControlToolkit; using System.Data.SqlClient; using System.Data; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO Imports AjaxControlToolkit Imports System.Data.SqlClient Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this.BindGrid(); } } private void BindGrid() { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection conn = new SqlConnection(constr)) { using (SqlDataAdapter sda = new SqlDataAdapter(&#34;SELECT * FROM tblFilesPath&#34;, conn)) { DataTable dt = new DataTable(); sda.Fill(dt); gvImages.DataSource = dt; gvImages.DataBind(); } } } protected void OnUploadComplete(object sender, AjaxFileUploadEventArgs e) { string fileName = Path.GetFileName(e.FileName); string filePath = &#34;~/Uploads/&#34; + fileName; AjaxFileUpload11.SaveAs(Server.MapPath(&#34;~/Uploads/&#34; + fileName)); string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;INSERT INTO tblFilesPath VALUES(@Name, @Path) &#34;, con)) { cmd.Parameters.AddWithValue(&#34;@Name&#34;, fileName); cmd.Parameters.AddWithValue(&#34;@Path&#34;, filePath); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } this.BindGrid(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Me.BindGrid() End If End Sub Private Sub BindGrid() Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using conn As SqlConnection = New SqlConnection(constr) Using sda As SqlDataAdapter = New SqlDataAdapter(&#34;SELECT * FROM tblFilesPath&#34;, conn) Dim dt As DataTable = New DataTable() sda.Fill(dt) gvImages.DataSource = dt gvImages.DataBind() End Using End Using End Sub Protected Sub OnUploadComplete(sender As Object, e As AjaxFileUploadEventArgs) Dim fileName As String = Path.GetFileName(e.FileName) AjaxFileUpload11.SaveAs(Server.MapPath(Convert.ToString(&#34;~/Uploads/&#34;) &amp; fileName)) Dim filePath As String = &#34;~/Uploads/&#34; &amp; fileName AjaxFileUpload11.SaveAs(Server.MapPath(&#34;~/Uploads/&#34; &amp; fileName)) Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO tblFilesPath VALUES(@Name, @Path) &#34;, con) cmd.Parameters.AddWithValue(&#34;@Name&#34;, fileName) cmd.Parameters.AddWithValue(&#34;@Path&#34;, filePath) con.Open() cmd.ExecuteNonQuery() con.Close() End Using End Using Me.BindGrid() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/k6JBhkj.jpg" alt="" width="330" height="402" /></p>https://www.aspforums.net:443/Threads/115491/Save-AjaxFileUpload-file-in-folder-and-path-in-Database-in-ASPNet/https://www.aspforums.net:443/Threads/115491/Save-AjaxFileUpload-file-in-folder-and-path-in-Database-in-ASPNet/Tue, 17 Jul 2018 06:24:11 GMT