My ASP.NET FileSystem Browser Revisited


More than 2 years ago I wrote this article and submitted it in CodeProject detailing how you can build a FileSystem Browser in ASP.NET. The article talks about how newbie ASP developers moving to ASP.NET might code the solution and how somebody a little bit more familiar with ASP.NET would build the same application in lesser code.


Somebody emailed me about my article yesterday asking for some guidance. This lead me to inspect my old article. The first thing i said to myself after seeing my old code is ‘Yikes! I did that?’. Yup, it was that horrible. The solution works, its functional based on the need but I knew i could clean it up and code it much better if i had the chance to do it a second time around. That chance happened today.


I haved changed the way i read folders(before it was using query strings). I have replaced that logic by placing the path inside my LinkButton CommandArgument property. How i pass the FileSystemInfo[] to the grid(it was using an intermediate datatable) and the type of control that displays the data(it was using a datagrid before now we are using a gridview). I’ve also added a breadcrumb like control to track the users location and made it a little bit prettier by adding icons instead of plain text descriptions.


I’ll be updating this constantly based on the request I haved received from my original article. The most common request is sorting which I will add on the next release.


Hopefully this version is less crappier than the last.


*Update*


Thanks to Andreas Haydeck for pointing out a bug in the BuildNavigatorPath method that causes the navigator path not to show the proper folder location. This has been fixed and the code in this article has been updated.


Download the latest source here: KeithRull.FileSystemManagerRevisited.zip (6.57 KB)

7 comments

  1. Ivan

    Hello Keith! I liked ur FileSystem browser very much and want to use it on my website. But i can’t make ur application work – i always get "You dont have access to view this folder." I’ve changed path from "c:Dell" to "test", granted all access to this folder, but nothing i got – still no access. I’m not a programmer, just user, so please, explain me what to do?
    Thanks in advance.

    P.S.: sorry for bad English, i’m from Russia.

  2. Keith Rull

    Hi,

    what you could do is change the the variable CONST_RootFolder from this:
    private string const CONST_RootDirectory = @"C:Dell";

    to this: private string CONST_RootDirectory = String.Empty;

    then change the page_load event to this:
    protected void Page_Load(object sender, EventArgs e)
    {
    //this is your initial path
    CONST_RootDirectory = this.MapPath("");
    if (!IsPostBack)
    {
    ShowFolderContents();
    }
    }

    what the code above does is that it sets the CONST_RootDirectory variable to the applications path which in your case would be:

    //this code defaults the folder brower to a folder called test
    CONST_RootDirectory = this.MapPath("test");

    HTH

  3. Brendan

    great post!
    This is what i was looking for. I am new to programming and this gives me a nice example and starting point for a project I am working on.
    Thanks!

Leave a Reply