如何从.Net的Intranet下载PDF文件? [英] How to download PDF file from intranet in .Net?

查看:70
本文介绍了如何从.Net的Intranet下载PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题问题。

我想要一个按钮,单击该按钮将下载pdf文件,该文件存储在其他Intranet服务器中。

I want to have a button that click it will download the pdf file where the file is stored in the other intranet server.

我尝试使用以下代码从其他Intranet文件中下载pdf文件。

I try to use the code below to download the pdf file from other intranet's file.

Response.Clear()
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", "attachment; filename=Test.pdf")
Response.BinaryWrite(System.IO.File.ReadAllBytes("\\intranetServer\Test.pdf"))
Response.End()

我不知道这是代码的问题还是其他问题?

I dont know it's code's problem or something else?

也许IIS需要设置一些配置?

Maybe IIS need to set something config?

我不知道要实现它。

推荐答案

使用 My.Computer.Network.DownloadFile

例如,您可以执行以下操作:

For example you could do:

My.Computer.Network.DownloadFile("\\intranetServer\Test.pdf","Path\Folder\file.pdf")

否则,您可以使用 System.Net.WebClient

这将使您跟踪进度并拥有更多控制权,例如:

This will let you track progress and have more control for instance:

Dim wc As System.Net.WebClient
wc = New System.Net.WebClient()
wc.DownloadFileAsync(New Uri("\\intranetServer\Test.pdf";), "Path\Folder\file.pdf")

PS:我不确定您可能需要<$的Intranet URI的结构c $ c> Net.Tcp://

PS: I'm not sure about the structure of the URI for intranet you might need Net.Tcp://

如果您想保留自己的解决方案,请尝试使用此功能并记住要确保IIS对所有人都是可见的,并且可以正确迁移Uri需要使用 file://

If you want to keep your solution try to use this and remember you need to make sure the IIS is visible to everyone and structure the Uri correctly might need to use the file:// !

Private Sub WriteFile(filepath As String, fileName As String, contentType As String, response As HttpResponse)
    response.Buffer = True
    response.Clear()
    response.ContentType = contentType
    response.Charset = "iso-8859-1"
    response.HeaderEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")

    Dim extension As String = System.IO.Path.GetExtension(fileName)
    response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & fileName)

    response.WriteFile(filepath)
    response.Flush()
End Sub

这篇关于如何从.Net的Intranet下载PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆