.net下载主机局域网的某个文件
需求大概是这样的:
有个下载按钮,点击后下载与服务器在同一个局域网里的电脑(电脑名:zyd)中的共享文件:开发计划.mpp
写出以下代码:
string fileName = "开发计划.mpp";//客户端保存的文件名 string filePath = Server.MapPath("zyd??开发计划.mpp"); //路径 FileInfo fileInfo = new FileInfo(filePath); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.WriteFile(fileInfo.FullName); Response.Flush(); Response.End();