日期:2014-05-19  浏览次数:20553 次

急急!求文件下载的方案
条件
1:网站程序放在E盘,
2:被客户下载的文件放在D:盘

如果下载的文件放在网站的目录内,很容易解决.
现在是放在不同的盘内.不知道如何解决!
需要用链接的方式进行下载(就是客户点击需要下载的文件名,如果是txt...文件,浏览器直接打开,像rar等文件,弹出保存对话框.
谢谢

------解决方案--------------------
http://www.cnblogs.com/TonyJoule/archive/2007/04/03/90585.html#Post
------解决方案--------------------
string filename = Path.GetFileName( "d:/ty/test.rar ");
string lencodefilename =System.Web.HttpUtility.UrlEncode(filename);
int BufSize = 51200;
string lfilename = "d:/ty/test.rar ";

FileStream fs=new FileStream(lfilename,FileMode.Open,FileAccess.Read,FileShare.Read,BufSize);


Response.Expires = -1;
Response.BufferOutput = true;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader( "Content-Disposition: ", "attachment;filename= " + lencodefilename);
try
{
byte[] ReadBuf = new Byte[BufSize];
fs.Seek(0,SeekOrigin.Begin);
int i =0;
int k = (int)(fs.Length);
while ( i <k)
{
if (i+BufSize <=k)
{
fs.Read(ReadBuf,0,BufSize);
Response.BinaryWrite(ReadBuf);
i=i+BufSize;
}
else
{
byte[] EndBuf =new Byte[k-i];
fs.Read(EndBuf,0,k-i);
Response.BinaryWrite(EndBuf);
i=k;
}
}
}
catch
{
}
fs.Close();
Response.End();

我刚搞的!这样搞定!你再根据你的需要改改!
------解决方案--------------------
string filename = "a.txt ";

if (filename != " ")
{

string path = Server.MapPath(filename);

System.IO.FileInfo file = new System.IO.FileInfo(path);

if (file.Exists)
{

Response.Clear();

Response.AddHeader( "Content-Disposition ", "attachment; filename= " + file.Name);

Response.AddHeader( "Content-Length ", file.Length.ToString());

Response.ContentType = "application/octet-stream ";

Response.Filter.Close();

Response.WriteFile(file.FullName);


Response.End();

}

else
{

Response.Write( "This file does not exist. ");

}

}

------解决方案--------------------
1、可以加一个虚拟目录,这个虚拟目录指向实际的下载用的文件夹。

2、尽量要求上传前先用rar压缩一下。不行的话就在程序里面判断,自动压缩。
------解决方案--------------------
jyk:
你做过“在程序里面判断,自动压缩”?帖个例子出来让我学习一下 :)
------解决方案--------------------
安装好WinRar,因后在asp.net里面调用rar的命令就可以实现目标了。
------解决方案--------------------

------解决方案--------------------
up
------解决方案--------------------
up
------解决方案--------------------
程序压缩
Process p = new Process() ;
p.StartInfo = new ProcessStartInfo( "C:\\Program Files\\WinRAR\\WinRAR.exe ", "a c:\a.rar c:\a.txt ");