System.UnauthorizedAccessException: Access to the path "" is denied

ToGetHelp

New member
Joined
Aug 12, 2021
Messages
2
Programming Experience
10+
I have problem to open PDF files stored at a folder in different server. Would like to know is it possible to open file from different server? The folder at the other server already being shared with the permissions required but still not able to open the file. I am able to get into the folder and open the file using Windows Explorer at the program server.

Thank you.
 
Sorry, here is the coding.

This is to get to the path to get the file name

Private Sub enablePanel(ByVal blnStatus As Boolean, ByVal path As String)

PanelLink.Visible = True

Dim filename As String = ""
Dim FILETYPE As String = ""
Dim filePath As String = ""
Dim strHTMLlink As String = "<P align=""left""><ul>"
Dim count As Integer = 0

Dim userName As String = System.Configuration.ConfigurationManager.AppSettings("DataServerID")
Dim password As String = System.Configuration.ConfigurationManager.AppSettings("DataServerPW")
Dim domain As String = System.Configuration.ConfigurationManager.AppSettings("DataDomain")

Dim d As DirectoryInfo = New DirectoryInfo(path)
Dim tokenHandle As New IntPtr(0)

Try

If LogonUser(userName, domain, password, 9, 0, tokenHandle) Then

Dim newId As New WindowsIdentity(tokenHandle)
Using impersonatedUser As WindowsImpersonationContext = newId.Impersonate()
'perform impersonated commands

If Not Directory.Exists(path) Then

lblError.Visible = True
lblError.Text = "Attachment not found, please contact EDGENTA IT support."
Exit Sub

Else

For Each File As FileInfo In d.GetFiles("*.pdf")
strHTMLlink = strHTMLlink & "<li><a href=""FileOpen.aspx?fileName=" & File.Name & """>" & File.Name & "</a><br><br></li>"
count = count + 1
strFilename = File.Name
Next

End If

End Using

CloseHandle(tokenHandle)

Else

lblError.Text = "Logon failed"

End If

Catch ex As Exception

lblError.Text = ex.Message

End Try

If count = 1 Then

If strPO_num <> "" Then
strFolderPath = path
ElseIf strGRN_num <> "" Then
strFolderPath = path
ElseIf strRRNum <> "" Then
strFolderPath = path
End If

showFile()

Exit Sub

ElseIf count = 0 Then
lblError.Visible = True
lblError.Text = d.FullName '"Attachment not found, please contact EDGENTA IT support."
End If

strHTMLlink = strHTMLlink & "</ul></P>"
Label1.Text = strHTMLlink

If strPO_num <> "" Then
Session("FilePath") = path
ElseIf strGRN_num <> "" Then
Session("FilePath") = path
ElseIf strRRNum <> "" Then
Session("FilePath") = path

End If

End Sub


This is to open the file

Private Sub showFile()

Dim username As String = ConfigurationManager.AppSettings("DataServerID")
Dim UserPassword As String = ConfigurationManager.AppSettings("DataServerPW")
Dim strFileExt As String
Dim FilePath As String = strFolderPath & strFilename

strFileExt = UCase(getextension(strFilename))
Response.AddHeader("Content-disposition", "inline;filename=" & strFilename)
Response.ContentType = getMimeType(strFileExt)
Response.WriteFile(FilePath)
Response.Flush()
Response.End()

End Sub

The error indicated at the yellow highlighted line.
 

Latest posts

Back
Top