c# 從一個服務器 訪問另外一個服務器上的文件


頁面調用 

function fnOpen(path) {
window.open("~/FileHelp.ashx? url=");
//window.open(url);
}

 

后台一般處理程序  

var myWebClient = new WebClient();
var url = context.Request["url"];
var cread = new NetworkCredential("賬號", "密碼", "domain");
myWebClient.Credentials = cread;
var fs = new FileStream(@"", FileMode.Open, FileAccess.Read);

byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
context.Response.ContentType = "application/octet-stream";
//通知瀏覽器下載文件而不是打開
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("sf.jpg", System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();

 

 

  • 首先我們要在服務器本地上訪問到 對應的文件夾,否則 你怎么做 都是無效的

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM