Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I need to open PDF file  which are stored in different Server in same network
environment using asp.net webpage

Inside the application Folder - No issue, can view on ASP.net page
../Doc_Uploads/FormsOLController.pdf

external Drive in same Network (In premise) cannot Open or view in ASP.net page
\\Sils-home\j-disk-3\pdf\FormsOLController.pdf

Please advice me.

Thank you 
Maideen


What I have tried:

What I did it

        Dim embed As String = "<object data=""{0}"" type=""application/pdf"" width=""100%"" height=""800px"">"
        embed += "If you are unable to view file, you can download from <a href = ""{0}"">here</a>"
        embed += " or download <a target = ""_blank"" href = ""http://get.adobe.com/reader/"">Adobe PDF Reader</a> to view the file."
        embed += "</object>"
        'ltEmbed.Text = String.Format(embed, ResolveUrl("Finance_Report_Invoice.pdf"))
        ltEmbed.Text = String.Format(embed, ResolveUrl(Me.txtFilePath.Text))



Inside the application Folder - No issue, can view on ASP.net page
../Doc_Uploads/FormsOLController.pdf

external Drive in same Network (In premise) cannot Open or view in ASP.net page
\\Sils-home\j-disk-3\pdf\FormsOLController.pdf
Posted
Updated 4-Feb-21 23:05pm

1 solution

ResolveUrl resolves a URL relative to the current page. It will not change a UNC path.

Which means that the user browsing your application would need to have access to the specified UNC path in order to be able to open that path.

You'll also find that most browsers will refuse to embed a local file, such as a UNC path, into a web page served over HTTP or HTTPS, since this would be a security vulnerability.

Instead of trying to embed the UNC path, you need to create a handler in the same site to load the file and write it to the response. Then point your <object> tag to that handler. You will need to ensure that your application pool is running as a user with permissions to access the file.
VB.NET
<%@ WebHandler Language="VB.NET" %>

Imports System.IO
Imports System.Web

Public Class DocumentHandler : Implements IHttpHandler
    Public ReadOnly Property IsReusable As Boolean
        Get
            Return False
        End Get
    End Property
    
    Public Sub ProcessRequest(ByVal context As HttpContext)
        Dim fileName As String = Path.GetFileName(Request.QueryString("file"))
        Dim filePath As String = Path.Combine("\\Sils-home\j-disk-3\pdf\", fileName)
        context.Response.TransmitFile(filePath)
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900