update link list when file is added.

Posted on 2014-08-25
Last Modified: 2014-08-29
I am neededing to create a web page that is essentially a list of files as hyperlink. I was wondering is there a way that when a file is added to the particular folder it would automatically get linked on the page?
Question by:jlcannon
    LVL 58

    Expert Comment

    Would make more sense to store the file names in a db and build the page from the db
    When a file is uploaded add a new entry to the db for it.
    LVL 32

    Accepted Solution

    You'll want to use the file system object, here's an example where it'll list all files in the current folder:

    Dim strPathInfo, strPhysicalPath
      strPathInfo = Request.ServerVariables("PATH_INFO")
      strPhysicalPath = Server.MapPath(strPathInfo)
      Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.GetFile(strPhysicalPath)
      Set objFolder = objFile.ParentFolder
      Set objFolderContents = objFolder.Files
      <TITLE>Display Directory</TITLE>
    <TABLE cellpadding=5>
     <TR align=center>
      <td align=left>File Name</td>
      <td>File Size</td>
      <td>Last Modified</td>
      For Each objFileItem In objFolderContents
        Response.Write "<TR><TD align=left>"
        Response.Write objFileItem.Name 
        Response.Write "</TD><TD align=right>" 
        Response.Write objFileItem.Size 
        Response.Write "</TD><TD align=right>" 
        Response.Write objFileItem.DateLastModified 
        Response.Write "</TD></TR>"

    Open in new window


    Author Comment

    When I use the file system object i keep getting the following error:

    Server.MapPath() error 'ASP 0171 : 80004005'

    Missing Path

    /technology/QCPlanIndex/QCPlanIndexStadeBeta.asp, line 7

    The Path parameter must be specified for the MapPath method.

    I am putting the network file path in here:

    strPathInfo = Request.ServerVariables("\\Server\Folder")

    Is this ocrrect?
    LVL 32

    Expert Comment

    by:Big Monty
    can you confirm which of the options below pertains on where the folder is that you want listed:

    1) the folder is the same where the page is loading from
    2) the folder is within another folder from within your site
    3) the folder is OUTSIDE of where your site runs from

    Your line of code where you set the strPathInfo is indeed incorrect. The Request.ServerVariables object can only contain certain preset values. You can have a look here to understand how it's used.

    if the folder you want listed somewhere within the site, then it'll be easy to set up, just post the relative url of the folder. If it's outside the site, the you'll need to create a virtual folder within your site to point to it, which is only a bit more complex to set up.

    Author Comment

    the folder is outside where the site runs.
    LVL 32

    Expert Comment

    by:Big Monty
    ok, then follow the directions in the link below to set up what's called a virtual directory (or folder):

    This is for IIS7, if you have a different version, let me know and I'll get you instructions for it. once you have the virtual directory set up (don't forget to set the permissions as well), change your code from

    strPathInfo = Request.ServerVariables("PATH_INFO")
    strPhysicalPath = Server.MapPath(strPathInfo)

    Open in new window


      strPathInfo = "/nameOfVirtualDirectory/"
      strPhysicalPath = Server.MapPath(strPathInfo)

    Open in new window

    LVL 52

    Assisted Solution

    by:Scott Fell, EE MVE
    >the folder is outside where the site runs.

    If you just give permissions to the IIS_IUSER account, there is no need to make a virtual directory.  Once you do that, you can use fso to read the folders and / or files in that directory.   I do this for uploading files for instance.  When I upload a file, I move it outside the public www and use fso to save it and call it up later.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Read about why website design really matters in today's demanding market.
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now