0

iv made a web forum, as i have lots of folders on my local drive i can now search for any folders i want on webpage.

Now am looking to add a link to the results of the search so it takes me directly to the folder.

My code in c#:

protected void List_Dirs(string searchStr = null)
    {
        try
        {
            MainContentLocal.InnerHtml = "";
            string[] directoryList = System.IO.Directory.GetDirectories("\\\\myfiles\\Web");
            int x = 0;
            foreach (string directory in directoryList)
            {

                if (searchStr != null && searchStr.Length > 1)
                {
                    UserInfo.Text = "Your Search for :  <strong>" + SearchPhrase.Text + "</strong>  returns  ";
                    if(directoryP.ToLower().Contains(searchStr.ToLower()))
                    {
                        MainContentLocal.InnerHtml += directoryP + "<br />";
                        x++;
                    }
                }
                else
                {
                    MainContentLocal.InnerHtml += directoryP + "<br />";
                }
            if (searchStr != null && searchStr.Length > 1)
            {
                UserInfo.Text += "<strong>" + x.ToString() + "</strong> results";
                UserInfo.CssClass = "userInfo";
            }
        }
        catch(Exception DirectoryListExp)
        {
            MainContentLocal.InnerHtml = DirectoryListExp.Message;
        }
    }

When i enter something is search i will get a list of folders like:

Your Search for : project returns 2 results
job234 project234 Awards
job323 project game

now is there any way for me to click the result so i can open a window explore on the webpage

Thanks

3 Answers 3

0

You can create links like <a href="ThisScript.aspx?folder=project234">project234</a>.

string folder = "\\\\myfiles\\Web";

if (string.IsNullOrWhiteSpace(Request["folder"])) {
  // Folder clicked

  folder = string.Format("{0}{1}", folder, Request["folder"]);
  Process.Start(folder);
}

string[] directoryList = System.IO.Directory.GetDirectories(folder);

Then it will open it on the server. So if it really is local, than it will work. If there is no security problem. But I'm not sure. You can also use file:// links (as Ryan Mrachek notes), but browsers are not happy to let you open them.

2
  • sorry i want a window explorer folder to come up from my search result when i click
    – al123
    Mar 6, 2014 at 12:21
  • I've edited my answer, looks at the Process.Start(folder) part
    – KoalaBear
    Mar 6, 2014 at 12:29
0

If your result is a file, you can open that file programmatically through the Process class by invoking Process.Start("C:\\MyResults.txt"). This will open the results in the default text editor. In the same way, you can also open a web page by inserting passing a Url to Process.Start. I hope this is what wanted.

0

our file urls are malformed. It should be:

file:///c:/folder/ Please refer to The Bizarre and Unhappy Story of File URLs.

This works for me:

link When you click Link, a new Windows Explorer window is opened to the specified location. But as you point out, this only works from a file:// URL to begin with.

A detailed explanation of what is going on can be found here. Basically this behavior by design for IE since IE6 SP1/SP2 and the only way you can change it is by explicitly disabling certain security policies using registry settings on the local machine.

So if you're an IT admin and you want to deploy this for your internal corporate LAN, this might be possible (though inadvisable). If you're doing this on some generic, public-facing website, it seems impossible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.