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.Get File Name of all Files inside Folder (Directory) using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="sureshMGR"> sureshMGR</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:Button Text=&#34;GetFileName&#34; runat=&#34;server&#34; OnClick=&#34;GetNames&#34; /&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; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void GetNames(object sender, EventArgs e) { string fileMessage = &#34;&#34;; DirectoryInfo dir = new DirectoryInfo(@&#34;D:\Users\Ajeet\Images\New folder&#34;); FileInfo[] fileinfo = dir.GetFiles(@&#34;*.jpg&#34;); foreach (FileInfo file in fileinfo) { fileMessage = fileMessage + &#34;\\n&#34; + file.Name; } ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;Message&#34;, &#34;alert(&#39;&#34; + fileMessage + &#34;&#39;);&#34;, true); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub GetNames(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim fileMessage As String = &#34;&#34; Dim dir As DirectoryInfo = New DirectoryInfo(&#34;D:\Users\Ajeet\Images\New folder&#34;) Dim fileinfo As FileInfo() = dir.GetFiles(&#34;*.jpg&#34;) For Each file As FileInfo In fileinfo fileMessage = fileMessage &amp; &#34;\n&#34; &amp; file.Name Next ScriptManager.RegisterStartupScript(Me, Me.GetType(), &#34;Message&#34;, &#34;alert(&#39;&#34; &amp; fileMessage &amp; &#34;&#39;);&#34;, True) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/YLQtE77.jpg" alt="" width="251" height="381" /></p>https://www.aspforums.net:443/Threads/159998/Get-File-Name-of-all-Files-inside-Folder-Directory-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/159998/Get-File-Name-of-all-Files-inside-Folder-Directory-using-C-and-VBNet-in-ASPNet/Wed, 15 May 2019 05:06:52 GMT