62,041
社区成员
发帖
与我相关
我的任务
分享
#region 文件下载
public bool DownLoadFile(string localPath, string hostURL, int byteCount, string userID, long cruuent)
{
bool result = true;
string tmpURL = hostURL;
byteCount = byteCount * 1024;
hostURL = tmpURL + "&npos=" + cruuent.ToString();
System.IO.FileStream fs;
fs = new FileStream(localPath, FileMode.OpenOrCreate);
if (cruuent > 0)
{
//偏移指针
fs.Seek(cruuent, System.IO.SeekOrigin.Current);
}
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(hostURL);
if (cruuent > 0)
{
request.AddRange(Convert.ToInt32(cruuent)); //设置Range值
}
try
{
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = request.GetResponse().GetResponseStream();
byte[] nbytes = new byte[byteCount];
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, byteCount);
while (nReadSize > 0)
{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, byteCount);
}
fs.Close();
ns.Close();
}
catch(Exception ex)
{
LOG.Error("下载" + localPath + "的时候失败!" + "原因是:" + ex.Message);
fs.Close();
result = false;
}
return result;
}
#endregion
把代码行号粘过来,27行有错,是不是少了或者多了个“)”,或者没有结束符“;”好好的检查下
using 下载及权限控制.dat.UserDateTableAdapters;
namespace 下载及权限控制.ashx
public void FileDownLoad(string fullFileName)
{
FileInfo downFiel = new FileInfo(fullFileName);
string filepath = Server.MapPath("DownFile"+"//"+fullFileName);
FileStream fs = new FileStream(filepath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fullFileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}