displaying a file from network path rather than application path

I am trying to display a pdf file using this code:

 <object class="ss-pdfjs-viewer" id="pdfDocument" runat="server" data= "Documents/test1.pdf" type="application/pdf" allowfullscreen webkitallowfullscreen  >
                    <iframe class="ss-pdfjs-viewer" id="test"    src="https://docs.google.com/viewer?url=https://localhost:44307/WebForm1&embedded=true&allowDownload=true&allowPrint=true" allowfullscreen webkitallowfullscreen></iframe>
              </object>

The above code works fine. The issue is this pdf file called test1.pdf is stored in my application path. Is it possible to show a pdf file from a network path instead of the application path for e.g. if I have test1.pdf file stored at this location:
\web-dtestpathtest1.pdf.

what should I do if I need to display this pdf file from my network path rather than application path. I tried doing this and it didnt work, it didnt display anything on the web page:
 <object class="ss-pdfjs-viewer" id="pdfDocument" runat="server" data= "\web-dtestpathtest1.pdf" type="application/pdf" allowfullscreen webkitallowfullscreen  >
                    <iframe class="ss-pdfjs-viewer" id="test"    src="https://docs.google.com/viewer?url=https://localhost:44307/WebForm1&embedded=true&allowDownload=true&allowPrint=true" allowfullscreen webkitallowfullscreen></iframe>
              </object>

any help will be greatly appreciated.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to give it a file protocol in front of the UNC path, otherwise the browser doesn’t know how to handle that.

Notice the file://\web-dtestpathtest1.pdf at the two places in the below markup.

<object class="ss-pdfjs-viewer" 
        id="pdfDocument" 
        runat="server" 
        data= "file://\web-dtestpathtest1.pdf" 
        type="application/pdf" 
        allowfullscreen webkitallowfullscreen  >
    <iframe class="ss-pdfjs-viewer" 
            id="test"    
            src="https://docs.google.com/viewer?url=file://\web-dtestpathtest1.pdf&embedded=true&allowDownload=true&allowPrint=true" allowfullscreen webkitallowfullscreen>
    </iframe>
</object>

In my local testing this works for me but there are plenty of cases described where it doesn’t, either due to browser security rules, local network/firewalls or other issue, so YMMV.

See this search to get an idea of problems ahead.

A better option might be to have your webserver open that file on that network location and then stream it to the client. For example Download/Stream file from URL – asp.net or many others that solve a similar problem.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x