• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

How to make PDF file list in directory clickable links

I have created a directory on the c drive of our web server where users on our local network will drop PDF files.

I have written a routine in asp.net [vb] that iterates through the files in that directory and builds a bulleted list with href links based on the file name and path.

Problem is, the href renders the files with links like this:
file:///C:/GrapevinePDFs/gv_1017.pdf

This is not a valid url or clickable link.

How do turn the file path shown above into a clickable link that visitors to the website can click on to view the PDFs?

Here is the code:

        Dim strGrapeVineHREF As String
        Dim strGrapeVineLink As String
        Dim strPath As String = "C:\GrapevinePDFs"
        For Each strGrapeVineHREF In System.IO.Directory.GetFiles(strPath, "*.pdf")

            strGrapeVineLink = GrapeVineVerboseName(strPath, strGrapeVineHREF)
            Dim li As New HtmlGenericControl("li")
            li.InnerHtml = "<a href=""" & strGrapeVineHREF & """ title=""View Grapevine Article"" target=""_blank"">" & strGrapeVineLink & "</a>"
            bulGrapevineArticles.Controls.Add(li)

        Next

Open in new window


0
jsvb1977
Asked:
jsvb1977
  • 3
  • 2
1 Solution
 
jsvb1977Author Commented:
oh yeah, here is the rendered HTML that the routine above spits out:

<ul id="ctl00_cpMainContent_bulGrapevineArticles" class="grapevinelist">
<li><a href="C:\GrapevinePDFs\gv_1017.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 17</a></li>
<li><a href="C:\GrapevinePDFs\gv_1018.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 18</a></li>
<li><a href="C:\GrapevinePDFs\gv_1019.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 19</a></li></ul>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
create a virtual folder under your app in ISS , say "GrapevinePDFs" pointing to c:\GrapevinePDFs

then link pdf files as

<li><a href="/GrapevinePDFs/gv_1017.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 17</a></li>
0
 
jsvb1977Author Commented:
Here is the entire block of code:
The Virtual Directory was the real solution, though...


        Dim strGrapeVine As String
        Dim strGrapeVineHREF As String
        Dim strGrapeVineLink As String
        Dim strPath As String = "C:\GrapevinePDFs\"
        For Each strGrapeVine In System.IO.Directory.GetFiles(strPath, "*.pdf")

            strGrapeVineHREF = strGrapeVine.Replace(strPath, "GrapevinePDFs/")
            strGrapeVineLink = GrapeVineVerboseName(strPath, strGrapeVine)
            Dim li As New HtmlGenericControl("li")
            li.InnerHtml = "<a href=""" & strGrapeVineHREF & """ title=""View Grapevine Article"" target=""_blank"">" & strGrapeVineLink & "</a>"
            bulGrapevineArticles.Controls.Add(li)

        Next

Open in new window

0
 
HainKurtSr. System AnalystCommented:
I did not write the code since I thought you could do it ;)
0
 
jsvb1977Author Commented:
Hainkurt,

I could see how my last post could have been construed as negative, but it was intended to give you praise.

I only posted the code I wrote so the next person might find it useful.

Thanks for everything!
Jason
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now