Hi, all

I'm working with an aspx file that's supposed to check on a directory (on the same server the file lives on) to see if a file of a particular name exists. Based on its response, it's either supposed to create a link to that file, or, well, do nothing. The code I'm working from is below:

  wc_result = web_client.DownloadData(\\server\dir\subdir\filename.pdf)
  Catch ex As Exception
  If Left(ex.Message, 6) = "THIS FILE EXISTS" Then
    link = "<a target='_blank' href='\\server\dir\subdir\filename.pdf'>Here is the file</a>"
  End If
End Try


If I insert a line to echo back the ex.Message, it tells me "The network path was not found". But, we're talking about the same server?!? I dont' think it's a permissions issue, or else it would have explicitly told me so.

I verified that the file does exist, and that the UNC path was accurate.

If I change the "If Left(ex.Message, 6) = "" criteria to "The ne", so it satisfies the boolean, it does create the "Here is the file" link, which does load the PDF, but the ex.Message still says that the network path is not found.

Any suggestions, please?


Recommended Answers

All 2 Replies

I generally use Server.MapPath... maybe something like this to check if a file exists...

Dim serverPath As String = Server.MapPath("~/FolderName/") + Path.GetFileName("~/FolderName/File.ext")
If File.Exists(serverPath) Then
End If

My apologies for the delayed response, but JorgeM got me going in the right direction, and after a lot of trial and error, I managed to get it to work. Here's what ended up working for me:

Dim path_to_pdf As String
path_to_pdf = Server.MapPath("/path/to/file/filename.pdf")
If System.IO.File.Exists(path_to_pdf) Then
  response.write("<a href='http://server/path/to/file/filename.pdf'>Completed</a>")
End If

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.