FileStream fileStream = new FileStream(@"c:\123.ini", FileMode.Open);
long fileSize = fileStream.Length;
Context.Response.ContentType = "application/octet-stream"; Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode("ini.ini", System.Text.Encoding.UTF8) + "\"");
Context.Response.AddHeader("Content-Length", fileSize.ToString());
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
fileStream.Close();
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
这是一个下载的功能,一点击时,它自弹出保存对话框来,我想让它直接保存到C:\HOST\目录里,怎么实现
求教了
long fileSize = fileStream.Length;
Context.Response.ContentType = "application/octet-stream"; Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode("ini.ini", System.Text.Encoding.UTF8) + "\"");
Context.Response.AddHeader("Content-Length", fileSize.ToString());
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
fileStream.Close();
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
这是一个下载的功能,一点击时,它自弹出保存对话框来,我想让它直接保存到C:\HOST\目录里,怎么实现
求教了
WebClient wc = new WebClient();
wc.DownloadFile('文件路徑', 'C:\HOST\');
不過這種方法在本機測試可以,但放在服務器上就不行了,
我還沒解決.好像和IIS的設置有關,具體的設置還沒搞明白希望有人能解決.
string saveAsToLocal = @"C:\Program Files\CSMARINE ERS\"; WebClient client = new WebClient();
string URL = path;
string fileName = URL.Substring(URL.LastIndexOf(@"\") + 1);
WebRequest myre = WebRequest.Create(URL);
client.DownloadFile(URL, saveAsToLocal + fileName);
解决了,用WebClient 就可以了
我是用ajax寫了在用戶端供用戶來選擇文件夾的,然後根據選擇下載,
但我的就是放在服務器上,用戶訪問下載就不行了.