代码:string remoteUrl=@"http://jhtchinajia/WebNetProcess/txt/";
int XRFbeginPage=(int)Session["XRFbeginPageTemp"];
int sheetAmount=(int)Session["sheetAmountTemp"];
                string[] filename=new string[sheetAmount];
                //string mystringWebSource=null;
//string downpath=@"d:\"+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+"\\";//choice path
string downpath=@"d:\temp\";
                //DirectoryInfo di=Directory.CreateDirectory(downpath);
for (int i=XRFbeginPage;i<=sheetAmount-XRFbeginPage;i++)
{
try
{
WebRequest myre=WebRequest.Create(remoteUrl+filename[i]);
}
catch (Exception exc)
{
Response.Write(exc.Message);
return;
}
                    filename[i]=i.ToString()+".txt";
                    WebClient myWebClient=new WebClient(); string mystringWebSource=remoteUrl+filename[i];
myWebClient.DownloadFile(mystringWebSource,downpath+filename[i]);                     Stream str=myWebClient.OpenRead(remoteUrl+filename[i]);
StreamReader reader=new StreamReader(str);
byte[] mbyte=new byte[1000000];
int allmybyte = (int)mbyte.Length; 
int startmbyte = 0; 
while(allmybyte>0) 

int m=str.Read(mbyte,startmbyte,allmybyte); 
if(m==0) 
break;    
startmbyte+=m; 
allmybyte-=m; 

                    FileStream fstr=new FileStream(downpath+filename[i],FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);

str.Close(); 
fstr.Close();  }
不知道为什么每次下载文件都是下载到服务器端的d:\temp下面
假设客户端已经有d:\temp文件夹,但是都不能下载文件到客户端,为什么?
各位老大帮帮忙

解决方案 »

  1.   

    string pathfile=targetfile;  //pathfile 是要下载的文件名称 
        System.IO.FileInfo file=new System.IO.FileInfo(pathfile); 
        Response.Clear(); 
        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));  
        Response.AddHeader("Content-Length", file.Length.ToString()); 
        Response.ContentType = "application/octet-stream"; 
        Response.WriteFile(file.FullName); 
        Response.End(); 
    这样把文件下载到客户端不是也很好吗。