简体   繁体   中英

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 eg if I have test1.pdf file stored at this location:

\\web-d\test\path\test1.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-d\test\path\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>

any help will be greatly appreciated.

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-d\test\path\test1.pdf at the two places in the below markup.

<object class="ss-pdfjs-viewer" 
        id="pdfDocument" 
        runat="server" 
        data= "file://\\web-d\test\path\test1.pdf" 
        type="application/pdf" 
        allowfullscreen webkitallowfullscreen  >
    <iframe class="ss-pdfjs-viewer" 
            id="test"    
            src="https://docs.google.com/viewer?url=file://\\web-d\test\path\test1.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM