asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

File Repository Weblication using IIS 4.0
By Amos El-Roy, Computer Insights Inc.
Rating: 3.5 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    This article will demonstrate how to create a file repository. The file repository accomplishes two things. First, it the allows the web administrator to delegate management of file availability to administrative users through FTP uploading rights without permissions for structural changes, and without having to modify the web site. Second, the repository protects the directory structure of the machine, avoiding problems that arise when directory browsing is turned on. The repository allows the web administrator to give additional instructions to the user, unlike the clumsy readme.txt stored in a FTP site. Finally the file repository only offers predefined file extensions for download, protecting the name of other extensions at the web administrators request.

    The file repository uses the FileSystem Object available in Internet Information Server version 4.0 to traverse a directory on the hard drive displaying certain file types through an Active Server page.

    What does it look like?

    Each dynamic directory listing through the ASP script is generated from the requested subdirectory. The script can work off of one or many separate subdirectories arranged in any structure under the file container directory.

    Figure 1 : The User's Perspective

    The application must be transparent to the users. For the person who wishes to download a file from the file repository the interface looks exactly like a simple HTML page containing a list of links to downloadable files.

    Setting Up

    To set up the application, create a dedicated directory on your web and make it an FTP virtual directory. This is required to allow your publishers or remote maintainer to logon into the container directories with their FTP clients for the purpose of file uploading. In order for this weblication to work you need to have two directories, each a child of a parent directory dedicated to the repository.

    One directory must have scripting privileges. This directory will contain the Active Server page that the user will call to view the repository. There is only one Active Server page, called dir.asp, for every repository implementation. The incoming parameter to it tells it what repository, or what subdirectory, to look in.

    Another directory needs to be created as a container for the subdirectories that will hold the files in the repository. For every repository a separate subdirectory needs to be created in the main parent. In the example a "files" directory is created; to have two repositories you will need to have a "files/rep1" and a "files/rep2."

    The files placed in the second directory will be displayed to the user. The parent directory needs to have read permissions, and contains the default page, the error pages and the graphics for the site.

    Follow these instructions for creating the directory structure:

    1. Create a parent directory called repository in c:\inetpub\
    2. Create a second directory out of the repository directory called scripts.
    3. Give the scripts directory scripting permission. Here is how to do it in IIS 4.0:
      1. Open up MMC.
      2. Expand the default web server.
      3. Expand the repository directory.
      4. Click on the scripts directory to highlight it.
      5. Right click and choose properties from the drop down menu.
      6. Click on the Directory Tab.
      7. Under Application Settings click on Create to create a web application.
      8. Under Application Settings make sure the Script radio button is highlighted.
      9. Click on OK.
      10. Leave MMC open; you will need to use it later.
    4. Now create another directory called files under repository parent directory.
    5. Give the files directory read permission. Here is how to do it in IIS 4.0:
      1. From the open up MMC.
      2. Expand the default web server.
      3. Expand the repository directory.
      4. Click on the files directory to highlight it.
      5. Right click and choose properties from the drop down menu.
      6. Click on the Directory Tab.
      7. Under Access Permission make sure that the Read box is checked.
      8. Click on OK.
      9. Close MMC.
    Once you have the directories created you can place dir.asp (shown in Example 1) in the scripts directory.

    Example 1 dir.asp

    
    <%
    if request.QueryString("path")="" then
      response.redirect("no_path.htm")
    end if
    
    subDir=request.QueryString("path")
    %><html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Directory Listing</title>
    </head>
    
    <body bgcolor="#FFFFFF">
    
    <% 
    if request.QueryString("title")="" or _
    isEmpty(request.QueryString("title")) then
    %>
    <h2 align="center"><%=subDir%></h2><br>
    <%else%>
    <h2 align="center"><%=request.QueryString("title")%></h2><br>
    <%end if%>
    
    <hr>
    
    <p><font size="2">Please click once on the description of the
    file that interests you. A dialog box will pop up asking:
    "What do you want to do with this file?
    " Select "<strong>open it</strong>."
    The file will be downloaded and your application will open.
    From here you may view it, print it, or
    save it (using the "<strong>save as...</strong>"
    option) to your hard drive.</font><br>
    </p>
    
    
    <hr>
    <div align="center"><center>
    
    <table border="0" cellpadding="6" cellspacing="0" width="550">
        <%
    	Set fileIO = CreateObject("Scripting.FileSystemObject")
        
    	path=Server.Mappath("/") 
        path=path & subDir 
    
    	
        Set Dir=fileIO.GetFolder(path)
        Set FileCollect=Dir.Files
        For Each item in FileCollect
          Fsize=item.size
    	Fname=item.name
          FileName=split(Fname,".",2)
    	title=FileName(0)
    	short_title=split(title,"_",2)
    	  
          link="../../" & subdir & FName
        %>
         <tr>
           <% select case FileName(1)
    	   Case "html"%>
             <td align="center">
             <img src="../icons/html.gif" width="32" height="32" border="0">
    	 </td>
    		<td align="default"><strong>
    		<a href="<%=link %>">
             <%=short_title(1)%></a>
             </strong></td>
             <td align="right"><%=Fsize%> bytes</td>
    
        <% Case "doc"%>
             <td align="center">
             <img src="../icons/word.gif" width="32" height="32" border="0">
    	 </td>
    		 <td align="default"><strong>
    		 <a href="<%=link %>">
             <%=short_title(1) %></a>
             </strong></td>
             <td align="right"><%=Fsize%> bytes</td>
    
        <% Case "xls"%>
             <td align="center">
             <img src="../icons/excel.gif" width="32" height="32" border="0">
    	 </td>
    		 <td align="default"><strong> 
             <a href="<%=link %>"><%=short_title(1) %></a>
             </strong></td>
             <td align="right"><%=Fsize%> bytes</td>
    
        <% Case "exe"%>
    		 <td align="center">
    		 <img src="../icons/pkzip.gif" 
             width="32" height="32" border="0"></td>
    		 <td align="default"><strong> 
             <a href="<%=link%>"><%=short_title(1) %></a>
             </strong></td>
             <td align="right"><%=Fsize%> bytes</td>
        <% end select %>
        </tr>
    <%
    Next
    set fileIO=Nothing
    %>
    </table>
    </center></div>
    </body>
    </html>
    
    
    
    The script starts by verifying that it has been passed a directory name in the URL header. This directory name is used to reference a child directory of the "files" directory. dir.asp displays all the files in the directory that is passed in.

    Making a list of links that point to individual directories can create all the repositories. A call can be issued by clicking directly on a link that includes the path to the directory, which the user wishes to browse. In any case the query string, by which the ASP script is called, has to include a variable named "Path" containing the relative path to the desired folder. If it is not present the file redirects to an error screen in the root of the repository, called no_path.htm. (There is an example of this file in the download available at the end of the article.) Place the file in the repository directory.

    The script allows a title for the browsing directory. For instance, the HTML link in Fig.2 would direct the dir.asp to the /lizards/big/ directory and title the resulting page as "Info about Big Lizards": Example 2 : Link to directory contents display

    
    <a href="file_browser.asp?title=Info+about+Big+Lizards&path=%5Crepository%5Cfiles%5Clizards%5Cbig">
    Big Lizards Directory</a>
    
    
    Note that the attached title and directory has to be URL encoded so that slashes become %5C and spaces become ‘+’ signs.
    After displaying the title, if it exists, the script proceeds to the File System Object creation. If the title is not in the query string, the script will default to displaying the path itself. The file system capabilities and related objects have been expanded in the VBScript engine implemented in IIS 4.0 (IIS 3.0 can be upgraded to comply with this expanded capability through an upgrade of the scripting engine to version 3.1 or higher)

    The Server.Mappath("/") method returns the physical path to the wwwroot directory on the server. The path to the folder containing the files is concatenated to the string of the root path. A directory object is then extracted through the use of the GetFolder method of the file system object. The file collection object, within the folder, is extracted, in turn, from the directory by accessing the Files property.

    Now all that is left to do is iterate through the file collection with the For Each loop and identify the files and their properties. For convenience the extension of the file is removed to be later replaced with a graphical icon identifying a known file type. Note that the split function parses the string and inserts its separated parts into an array. We use the Select case structure to check for expected file extensions and display the appropriate icon next to those files.

    File Naming Convention:

    To include information that can not be conveyed through the usual properties of the files we use a naming convention for the file names. To begin with we use long names. Note that the words should be spaced by underscores to minimize any potential problems. The underscores will not appear in the displayed name, because they are shown as a link and in most cases underscored by the browser. A date associated with the file, other than the file creation file, can be attached to the end of the descriptive name. If you wish you may expand on this convention and even use it to manipulate the files, sort them, or hide them. Each filename will start with a short unique code to identify it easily in a directory tree. This code, separated from the rest of the name with an underscore, is stripped away for display purposes.

    Download

    You can Download the code and create your own file repository.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    Proposion N2N
    Proposion N2N connects Microsoft .NET applications to Lotus Notes and Lotus Domino databases. This ADO.NET managed data provider allows you to perform blindingly fast queries and updates of Notes data from ASP.NET pages, .NET web services, Windows, or Mobile applications. An innovative SQL-like query language leverages the unique features of Notes and makes collaborative software accessible to relational database programmers.
    [Top]
    Other Articles
    Sep 15, 2005 - Building an Image Keyword System
    Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
    [Read This Article]  [Top]
    Apr 7, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 2
    In the second part of of his article on using MySQL with ASP.NET, Ziran Sun covers how to add a new MySQL user to the database server, assign the user the appropriate permissions, connect to the database, and build a simple ASP.NET page to perform a query.
    [Read This Article]  [Top]
    Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
    Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some other enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there's another viable alternative: MySQL.
    [Read This Article]  [Top]
    Jan 27, 2005 - Moving a Database from SQL Server 7.0 to SQL Server 2000
    Moving or copying a SQL Server database from one machine to another requires a lot of preparation in order to ensure a smooth transfer. In this article, Dina Fleet Berry examines the different methods and highlights the different issues associated with each of them.
    [Read This Article]  [Top]
    Jan 6, 2005 - Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
    There are many times when using SQL Server 2000 Query Analyzer to debug SQL statements is a better choice than debugging in Visual Studio .NET. In this article, Dina Fleet Berry explains why and walks you through the debugging process step-by step.
    [Read This Article]  [Top]
    Nov 24, 2004 - Persisting .NET Objects to SQL Server Using SQLXML and Serialization
    As a follow up to his article on retrieving objects from SQL Server using SQLXML and serialization, Gianluca Nuzzo discusses saving objects back to SQL Server using a schema definition file and updategrams.
    [Read This Article]  [Top]
    Sep 14, 2004 - Transaction Processing in ADO.NET 2.0
    One area that stands out when comparing ADO.NET 1.x to ADO.NET 2.0 is transaction processing. Bill Ryan shows just how easy transaction processing has become with the TransactionScope object in ADO.NET 2.0.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Sep 2, 2004 - Queue MSMQ Messages from SQL Server
    Learn how to create a console application to queue a message in Microsoft Message Queuing (MSMQ) and then use an extended stored procedure to call the console application from a SQL Server trigger.
    [Read This Article]  [Top]
    Aug 30, 2004 - Tuning Up ADO.NET Connection Pooling in ASP.NET Applications
    Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. This article shows how to monitor the connection pool, diagnose a potential problem, and apply the appropriate fix.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES