编写下载按钮时出错
private void DownLoadFile(string address, string filename){
WebClient client=new WebClient();
client.DownloadFile(address,filename);//运行到此处出错
//跟踪 address=D:\\源程序\\Cabin\\UpData\\b0c0a0d9-c419-4a90-bb26-d76470714a17_12.jpg filename=c:\\b0c0a0d9-c419-4a90-bb26-d76470714a17_12.jpg
Stream str=client.OpenRead(address);
StreamReader reader=new StreamReader(str);
byte[] mbyte=new byte[str.Length+1];
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(filename,FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);
str.Close();
fstr.Close();
} --------------------编程问答-------------------- private void DownFileExcel(string filename)
{//文件下载
string updata_url = System.Configuration.ConfigurationManager.AppSettings["UpdataUrl"].ToString();
string filepath = Server.MapPath(updata_url + filename);
try
{
WebRequest myre = WebRequest.Create(filepath);
string newfilename ="c:\\" + filename;//newfilename为存放本地的文件路径
DownLoadFile(filepath, newfilename);
}
catch (System.Exception ee)
{
string dd = ee.ToString();
Response.Write("文件无法下载");
}
} --------------------编程问答-------------------- 跟踪 address=D:\\源程序\\Cabin\\UpData\\b0c0a0d9-c419-4a90-bb26-d76470714a17_12.jpg
你这个不是Http资源,不能用WebClient.DownloadFile,为什么不直接用File.Copy
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- web.config文件中:<add key="UpdataUrl" value="../UpData/"/>
string filepath = Server.MapPath(updata_url + filename);
在我单机上运行时,它解析出来的 --------------------编程问答-------------------- 将来代码要上传到服务器上的
--------------------编程问答-------------------- D盘路径的斜杠确定是双斜杠?
补充:.NET技术 , C#