Click here to Skip to main content
Licence CC (ASA 2.5)
First Posted 26 Apr 2004
Views 86,102
Bookmarked 35 times

Simple Web Browse

By | 26 Apr 2004 | Article
File and directory browser application in ASP.NET.

Sample Image - webbrowse0070.jpg

Introduction

This article is about a simple directory & file browser for the web. The browser displays a list of files and directories of the directory where it is placed.

Using the script

  • Place the script file, default name Browse0070.aspx within the root / sub directory of your web server.
  • Rename the script if desired, and link to the script...
  • Example link.
    <A href="Browse0070.aspx">Browse</A>

How it Works

This is a rather simple script when it come to the actual core of the code... Loops are preformed for each directory / file entry with the directory it's been pointed to... For each directory it prints, it adds a link for that directory to itself, making the script able to surf though the file system. The snippet below displays the file output code...

//Ouput files
FileInfo[] oFiles = oDirInfo.GetFiles();
foreach(FileInfo oFile in oFiles){
    if(oFile.Name.ToLower()!=lsScriptName){
        iLen=oFile.Length;
        if(iLen>=1048960){iLen=iLen/1048960;sLen="mb";}else{i...
        sLen=Decimal.Round(iLen,2).ToString()+sLen;
        Response.Write("<TR><TD class=\"tdFile\"><A href=\""+...
    }
}

Features

  • Script is contained in one file for easy usage / implementation
  • Page title can be set via the title variable
  • Return link can be set via the link variable
  • Script can be renamed to any filename, e.g.. default.aspx
  • The name of the script file, will not appear in the output
  • Displays in KB and MB
  • Only displays the root and sub directory below itself for security

History

  • 28th April 2004 - Build 0070
    • Rewritten from VB.NET to C#, small visual and running changes.
    • Renamed from "File Browser" to "Web Browse".
    • Posted on CodeProject.
  • Build 0063
    • Optimizations and tidying of the code, moved to the build version system.
  • Build 0062
    • Added better error checking, now displays errors on the page.
  • Build 0061
    • Link now passes correctly when using a link from the crumb bar.
  • Build 0060
    • "link" option for returning to main page, etc.
    • Script produced errors when it encounters a write protected directory, now displays as "Access Denied" next to the name.
    • The title would reset after entering a directory, details are now retained from page to page when navigating.
  • Build 0030-0050
    • File size is displayed in KB and MB.
    • Left / right alignment in columns, instead of all left.
    • Added "title" option for returning to main page, etc.
    • New layout, colors, and tidied output.
    • First build to appear online.

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License

About the Author

aejw

Web Developer

New Zealand New Zealand

Member

C#, VB.net (Web and forms), SQL Server, MySQL, ASP, Win32 API, ...
Site: aejw.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 Pinmemberclodiny0:23 10 Mar '12  
QuestionPLease apply ajax in this PinmemberMember 82806352:52 17 Jan '12  
GeneralNetwork Shares PinmemberBIGDO3:08 21 Nov '07  
Questionbring back the VB version Pinmemberzenuke2:22 4 Jun '07  
AnswerRe: bring back the VB version Pinmemberaejw4:48 4 Jun '07  
GeneralGREAT! - please read: PinmemberAvshash22:48 8 Apr '07  
GeneralRe: GREAT! - please read: Pinmemberaejw2:42 9 Apr '07  
NewsNetwork Shares... Pinmemberaejw5:13 28 Mar '07  
GeneralThanks! Pinmemberstupidstanly4:59 14 Mar '07  
GeneralRe: Thanks! Pinmemberaejw23:51 14 Mar '07  
GeneralThanks! PinmemberUV20037:06 30 Apr '06  
GeneralDont write inline HTML PinmemberBobby Ryzhy12:21 14 Jul '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 27 Apr 2004
Article Copyright 2004 by aejw
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid