如何下载ASP.NET中另一台服务器上的文件? [英] How to download file that is on another server in ASP.NET?

查看:60
本文介绍了如何下载ASP.NET中另一台服务器上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

If e.CommandName = "Down" Then

         Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
         Dim lblDoc = TryCast(row.FindControl("lbllog"), Label).Text
         Dim cs = "172.16.16.21/"

         Dim lblDoca = cs + "D:/1 Application/MobileApp/Documents/B2C 158712858622501161001263110.jpg"
         ''Dim lblDoca = cs + lblDoc


         Response.ContentType = ContentType
         Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(lblDoca))
         Response.WriteFile(lblDoca)
         Response.End()





我尝试了什么:



实际上我想下载的图像是另一个server..how我可以下载它吗



What I have tried:

actually i want to download image which is another server..how can i download it

推荐答案

Dim webClient As New System.Net.WebClient()
webClient.DownloadFile("http://<serverPath>/<filename>.txt", "<localpath2save>")





例如:



< serverpath> :http://www.testserver.com(如=> http://192.168.9.99:1880/testfolder/test.txt)

< filename> :test

< localpath2save> :C:\\test.txt



For Example :

<serverpath> : http://www.testserver.com (like => http://192.168.9.99:1880/testfolder/test.txt)
<filename> : test
<localpath2save> : C:\\test.txt


1。您需要提供有效路径并包含响应修改内容类型以下载图像类型

2.在文件所在的其他服务器上,您需要有权访问该文件



1. You need to give valid path and include response modify the content type to download the image type
2. On the other server where file is located, you need to have permission to access the file

String filename = (String) request.getAttribute("fileName");
       response.setContentType("application/octet-stream");
       response.setHeader("Content-Disposition",
               "attachment;filename="+filename);


这篇关于如何下载ASP.NET中另一台服务器上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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