Hi sureshMGR,
Use DirectoryInfo class and get all the files using GetFiles method.
Now you can get the FileName using the FOREACH loop.
Refer below sample.
HTML
<asp:Button Text="GetFileName" runat="server" OnClick="GetNames" />
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void GetNames(object sender, EventArgs e)
{
string fileMessage = "";
DirectoryInfo dir = new DirectoryInfo(@"D:\Users\Ajeet\Images\New folder");
FileInfo[] fileinfo = dir.GetFiles(@"*.jpg");
foreach (FileInfo file in fileinfo)
{
fileMessage = fileMessage + "\\n" + file.Name;
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('" + fileMessage + "');", true);
}
VB.Net
Protected Sub GetNames(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim fileMessage As String = ""
Dim dir As DirectoryInfo = New DirectoryInfo("D:\Users\Ajeet\Images\New folder")
Dim fileinfo As FileInfo() = dir.GetFiles("*.jpg")
For Each file As FileInfo In fileinfo
fileMessage = fileMessage & "\n" & file.Name
Next
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Message", "alert('" & fileMessage & "');", True)
End Sub
Screenshot