1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Displaying PDF Files in a list

Discussion in 'C#' started by aquasonic, Jul 15, 2008.

  1. #1
    I have this code... which is great!

    It displays a list of all the PDF files within a folder... but this script will only show the files within the folder that the script is in...

    I want to show all PDF files within a folder called blueprint.

    Any ideas?

    <%
    		set FileSysObj=CreateObject("Scripting.FileSystemObject")
    		strFileAndPath = request.servervariables("SCRIPT_NAME")
    		strPathOnly = Mid(strFileAndPath,1 ,InStrRev(strFileAndPath, "/"))
    		strFullPath = server.mappath(strPathOnly)
    		set fldr=FileSysObj.GetFolder(strFullPath)
    		set FileList = fldr.Files
    		For Each FileIndex in FileList
    		'This bit includes only PDF files
    		if Lcase(right(FileIndex.Name, 4)) = ".pdf" then
    		Dim issue
    		issue = Left(FileIndex.name,Len(FileIndex.name)-4)
    		Response.Write("<li><A HREF='" & FileIndex.name & "'>" & issue & "</A></li>")
    		end if
    		Next
    	%>
    Code (markup):

     
    aquasonic, Jul 15, 2008 IP
  2. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just a guess, as I'm no expert, but changing the following line...

    
    strPathOnly = Mid(strFileAndPath,1 ,InStrRev(strFileAndPath, "/"))
    
    Code (markup):
    from the "/" at the end to be the folder name or path where you want it to search for or list the PDF files. :)
     
    LittlBUGer, Jul 15, 2008 IP
  3. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #3
    Are there subdirectories under the parent directory? If so, you need to loop through the SubFolders collection and get any and all .PDF files too. Here is a small snippet:

    Dim objFolder As Scripting.Folder
    Dim objFile As Scripting.File
    Dim objSubdirs As Scripting.Folders
    Dim objLoopFolder As Scripting.Folder

    Set objFolder = m_objFSO.GetFolder(strPath)
    For Each objFile In objFolder.Files
    If UCase$(Right$(objFile.ShortPath, 4)) = ".PDF" Then
    'Perform Business Rules
    End If
    Next objFile

    Set objSubdirs = objFolder.SubFolders
    For Each objLoopFolder In objSubdirs
    'Recursive Call or Code as Needed
    Next objLoopFolder

    Set objSubdirs = Nothing
    Set objFolder = Nothing
     
    Social.Network, Jul 15, 2008 IP
  4. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #4
    Nah - that would be way too easy! :p
     
    aquasonic, Jul 16, 2008 IP
  5. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #5
    Found the answer....

    Changed it to this:
     
    aquasonic, Jul 16, 2008 IP