如何使用asp.net实现资源的下载 请详细说明应该使用的控件以及各控件的属性设置!多谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #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 .NET实现下载功能 求asp.net使用WF的实例!! 前台和后台执行的顺序问题 如何在服务器端获取HTML控件 谁有实现日历的好的算法,给一个 ICollection,IList,IDictionary 有什么区别? 急等上传图片代码 急!急需高手指点!运行时灾难性故障 全部家当问菜鸟问题 为什么有SortExpression="学号"就出错呀!关于datagrid导出数据到excel时不能排序的问题,已经是第三次问了!! asp.net(C#)怎么让桌面任务栏浏览器图片闪烁变色 这个文件应该放在什么位置 求一url重定向规则
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