Hi EddieP,
Refer the below sample that full-fill your requirement. Also read the comments carefully to modify as per your website details.
HTML
<asp:TextBox runat="server" ID="txtSearch" />
<asp:Button ID="Button1" Text="Search File" runat="server" OnClick="Search" />
Code
C#
protected void Search(object sender, EventArgs e)
{
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(Server.MapPath("~/"));
System.IO.FileInfo[] fileInfos = directoryInfo.GetFiles(txtSearch.Text.Trim().ToLower() + ".aspx", System.IO.SearchOption.AllDirectories);
if (fileInfos.Length > 0)
{
List<string> availableFilePath = new List<string>();
foreach (System.IO.FileInfo fileInfo in fileInfos)
{
availableFilePath.Add(fileInfo.FullName);
}
foreach (string path in availableFilePath)
{
// This line of code open the file in chrome.
// You need to replace 'http://localhost:36828/926680_BrowseDirectory/' with the website address eg: 'http://www.EddieP.com/'
// Here i am opening the file in localhost. So i pass my local host address i.e. 'http://localhost:36828/926680_BrowseDirectory/'
// For the file to open in browser your website must be in running mode.
// So that it will open the file with the complete address eg: 'http://www.EddieP.com/Default.aspx' , 'http://www.EddieP.com/test/Default.aspx'
System.Diagnostics.Process.Start("chrome.exe", path.Replace(directoryInfo.FullName, "http://localhost:36828/926680_BrowseDirectory/"));
}
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "alert('No file found !')", true);
}
}
VB.Net
Protected Sub Search(sender As Object, e As EventArgs)
Dim directoryInfo As New System.IO.DirectoryInfo(Server.MapPath("~/"))
Dim fileInfos As System.IO.FileInfo() = directoryInfo.GetFiles(txtSearch.Text.Trim().ToLower() + ".aspx", System.IO.SearchOption.AllDirectories)
If fileInfos.Length > 0 Then
Dim availableFilePath As New List(Of String)()
For Each fileInfo As System.IO.FileInfo In fileInfos
availableFilePath.Add(fileInfo.FullName)
Next
For Each path As String In availableFilePath
' This line of code open the file in chrome.
' You need to replace 'http://localhost:36828/926680_BrowseDirectory/' with the website address eg: 'http://www.EddieP.com/'
' Here i am opening the file in localhost. So i pass my local host address i.e. 'http://localhost:36828/926680_BrowseDirectory/'
' For the file to open in browser your website must be in running mode.
' So that it will open the file with the complete address eg: 'http://www.EddieP.com/Default.aspx' , 'http://www.EddieP.com/test/Default.aspx'
System.Diagnostics.Process.Start("chrome.exe", path.Replace(directoryInfo.FullName, "http://localhost:36828/926680_BrowseDirectory/"))
Next
Else
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "message", "alert('No file found !')", True)
End If
End Sub