public void DownLoad(string FileName,Page R)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
if (FileName != "")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string path = R.Server.MapPath(FileName);
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
R.Response.Clear();
R.Response.AddHeader("Content-Disposition", "attachment; FileName=" + file.Name);
R.Response.AddHeader("Content-Length", file.Length.ToString());
R.Response.ContentType = "application/octet-stream";
R.Response.Filter.Close();
R.Response.WriteFile(file.FullName);
R.Response.End();
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
R.Response.Write("This file does not exist.");
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
示例 二:
private void NewDownLoad(string Path,string FileName)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{//Path为文件绝对路径,FileName为文件路径
FileStream fs=new FileStream(Path,FileMode.Open,FileAccess.Read);
BinaryReader r=new BinaryReader(fs);
Response.AddHeader("Content-Disposition","attachment;filename="+FileName);
Response.Charset="gb2312";
Response.ContentType="application/octet-stream";
Response.BinaryWrite(r.ReadBytes(Convert.ToInt32(fs.Length)));
Response.Flush();
fs.Close();
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
File.Delete(Path);
}
catch(System.Exception ee)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string ff=ee.ToString();
}
}
示例三:
![](/Images/OutliningIndicators/ContractedBlock.gif)
文件下载#region 文件下载
private void DownLoadFile(string address,string filename)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{//address 文件下载路径,filename文件存放的本地路径
WebClient client=new WebClient();
client.DownloadFile(address,filename);
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)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int m=str.Read(mbyte,startmbyte,allmybyte);
if(m==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
break;
}
startmbyte+=m;
allmybyte-=m;
}
FileStream fstr=new FileStream(filename,FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);
str.Close();
fstr.Close();
}
#endregion
posted @
2007-09-04 16:48
你约我交友网
阅读(
541)
评论()
编辑
收藏
举报