GridView控件中某一列实现文件下载! 有详细步骤么..谢谢. 解决方案 » 免费领取超大流量手机卡,每月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 <asp:HyperLinkField DataTextField="字段名称" DataNavigateUrlFields="标识字段" DataNavigateUrlFormatString="download.aspx?id={0}" />download.aspx按照上面的代码即可 在GridView控件中添加一列超链接按钮,超链接的URL为需要下载的文件地址! 要做一个会员系统和一个广告系统 javascript实现复写 急求!anychart画饼图实例 用最后50分求助关于两个脚本本时运行时出错的问题,请各位高手帮忙解决 讨论:DataGrid嵌套DataList,子DataList控件中的ItemDataBound事件的问题 做了个成绩管理系统。忽然发现还有一项很重要的工作没做??? 写自定义控件时候,能不把多了类写在一个文件?为什么有错误? asp网上考试系统 思归大哥,还有一小问题! 逆思维求TreeView中TreeNode父节点的问题(基于TreeView问题求解之四) 请问.net下如何处理并发? 有关后置代码
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