簡體   English   中英

從網絡路徑而不是應用程序路徑顯示文件

[英]displaying a file from network path rather than application path

我正在嘗試使用以下代碼顯示 pdf 文件:

 <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>

上面的代碼工作正常。 問題是這個名為 test1.pdf 的 pdf 文件存儲在我的應用程序路徑中。 是否可以從網絡路徑而不是應用程序路徑顯示 pdf 文件,例如,如果我有 test1.pdf 文件存儲在此位置:

\\web-d\test\path\test1.pdf. 

如果我需要從我的網絡路徑而不是應用程序路徑顯示這個 pdf 文件,我該怎么辦。 我試過這樣做,但沒有用,它沒有在 web 頁面上顯示任何內容:

 <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>

任何幫助將不勝感激。

你需要在 UNC 路徑前面給它一個文件協議,否則瀏覽器不知道如何處理它。

請注意以下標記中兩個位置的file://\\web-d\test\path\test1.pdf

<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>

在我的本地測試中,這對我有用,但是由於瀏覽器安全規則、本地網絡/防火牆或其他問題,有很多情況描述了它不起作用,所以 YMMV。

請參閱此搜索以了解未來的問題。

更好的選擇可能是讓您的網絡服務器在該網絡位置打開該文件,然后將 stream 文件發送到客戶端。 例如,從 URL - asp.net 或許多其他解決類似問題的文件下載/流式傳輸文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM