FileUpload控件有客户端下载功能么?
解决方案 »
- 如何实现xls导入到textbox里
- javascript Array()如何在在asp.net cs 上写
- treeview 作为功能树的问题(比较棘手)
- 我想用c#三层结构的oa换c#三层结构的全站程序学习。
- 一个刚ASP.NET入门的新手,想请各位高手指点一下,谢谢!!!
- 使用 SQL Server数据库搜索语句咱们写才能真正搜索到东西。另外良好的搜索系统是怎么Code出来的?
- ImageButton按钮
- 大家除了用asp.net做网站更多的是做什么软件?
- 为什么我的treeView作的树在ie6上运行的很正常!!!而在ie5上却有很多问题!!!是不是TreeView组件需要的ie5。5以上!!!
- 高分求教?为什么不能访问数剧库中的数剧?
- asp.net关于Fill: SelectCommand.Connection 属性尚未初始化的错误
- asp.net为什么修改textbox的内容(返回页面有显示更改的数据),但是数据库更新不了,求救啊!~!
protected void Button1_Click(object sender, EventArgs e)
{
Boolean fileOk = false;
//获取文件物理路径
string path = Server.MapPath("~/Account/");
//判断是否选择文件
if (FileUpload1.HasFile)
{
//取得文件扩展名
string exName = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
//限定文件类型
string[] allowExtn = { ".jpg", ".txt", ".gif" };
//对上传的文件的类型进行一个个匹对
for (int i = 0; i < allowExtn.Length; i++)
{
if (exName == allowExtn[i])
{
fileOk = true;
break;
}
}
////对上传文件的大小进行检测,限定文件最大不超过1M
//if (FileUpload1.PostedFile.ContentLength > 1024000)
//{
// fileOk = false;
//} if (!fileOk)
{
Response.Write("<script>alert('文件类型不对');</script>");
}
else
{
try
{
FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName);
Response.Write("<script>alert('上传成功');</script>");
}
catch
{ Response.Write("<script>alert('上传失败');</script>");
}
} }
看英文应该能猜到啊。。file...upload...又不是file..download
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