FileUpload控件上传文件代码(含视频文件)
来源:互联网 发布:淘宝 单行本 小椋ムク 编辑:程序博客网 时间:2024/05/22 06:04
if (this.FileUpload1.PostedFile.FileName == "")
{
MessageBox.alert(Page, "请选择上传文件!");
return;
}
try
{
//服务器端地址(使用时改成你的地址即可)
string Path = Server.MapPath("~/JiaoXueDaGang/updagang/");
//客户端路径
string filePath = this.FileUpload1.PostedFile.FileName;
//文件名称
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
string newfileName=others.GetZPName(fileName);
//上传的文件到服务器的路径
string serverPath = Path + newfileName;
//文件类型
string str = fileName.Substring(fileName.LastIndexOf(".") + 1);
//根据需要来改变类型
if (str != "jpg" && str != "rar" && str != "doc" && str != "xls" && str != "ppt")
{
MessageBox.alert(Page, "对不起,该类型文件不能上传!");
return;
}
//文件大小
int daxiao = FileUpload1.PostedFile.ContentLength / 1024;
//Response.Write(daxiao.ToString());
if (daxiao > 10240)
{
MessageBox.alert(Page, "只能上传小于10M的文件!");
return;
}
//上传文件
SqlParameter[] sp = {
new SqlParameter("@zname",txtr_Name.Text.Trim()),//名称
new SqlParameter("@type",type),//类型
new SqlParameter("@typeid",typeid),//类型id
new SqlParameter("@Path","../JiaoXueDaGang/updagang/"+newfileName),//文件地址
new SqlParameter("@adduser",Session["Uid"].ToString())//添加人
};
int i = SqlHelper.ExecuteNonQuery(Conn.ConnString, CommandType.Text, sql, sp);
if (i > 0)
{
new MessageBox().MsgBox1("上传成功", "Add.aspx");
}
else
{
MessageBox.alert(Page, "上传失败!");
}
}
catch (Exception ex)
{
MessageBox.alert(Page, ex.Message.ToString());
{
MessageBox.alert(Page, "请选择上传文件!");
return;
}
try
{
//服务器端地址(使用时改成你的地址即可)
string Path = Server.MapPath("~/JiaoXueDaGang/updagang/");
//客户端路径
string filePath = this.FileUpload1.PostedFile.FileName;
//文件名称
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
string newfileName=others.GetZPName(fileName);
//上传的文件到服务器的路径
string serverPath = Path + newfileName;
//文件类型
string str = fileName.Substring(fileName.LastIndexOf(".") + 1);
//根据需要来改变类型
if (str != "jpg" && str != "rar" && str != "doc" && str != "xls" && str != "ppt")
{
MessageBox.alert(Page, "对不起,该类型文件不能上传!");
return;
}
//文件大小
int daxiao = FileUpload1.PostedFile.ContentLength / 1024;
//Response.Write(daxiao.ToString());
if (daxiao > 10240)
{
MessageBox.alert(Page, "只能上传小于10M的文件!");
return;
}
//上传文件
this.FileUpload1.PostedFile.SaveAs(serverPath);
//将记录添加的数据库中
string sql = "INSERT INTO [dbo].[JiaoXueDaGang]([zname],[type],[typeid],[Path],[adduser])VALUES(@zname,@type,@typeid,@Path,@adduser)";SqlParameter[] sp = {
new SqlParameter("@zname",txtr_Name.Text.Trim()),//名称
new SqlParameter("@type",type),//类型
new SqlParameter("@typeid",typeid),//类型id
new SqlParameter("@Path","../JiaoXueDaGang/updagang/"+newfileName),//文件地址
new SqlParameter("@adduser",Session["Uid"].ToString())//添加人
};
int i = SqlHelper.ExecuteNonQuery(Conn.ConnString, CommandType.Text, sql, sp);
if (i > 0)
{
new MessageBox().MsgBox1("上传成功", "Add.aspx");
}
else
{
MessageBox.alert(Page, "上传失败!");
}
}
catch (Exception ex)
{
MessageBox.alert(Page, ex.Message.ToString());
}
注意:在上传视频文件的时候需要在web.config中添加配置信息
在<system.web></system.web>之间添加<httpRuntime executionTimeout="600" maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>
0 0
- FileUpload控件上传文件代码(含视频文件)
- 文件上传 含进度条(fileupload控件)
- 文件上传控件(FileUpload)
- FileUpload控件上传文件
- FileUpload文件上传控件
- 文件上传(含代码)
- FileUpload控件上传大文件
- FileUpload控件实现上传文件
- 用FileUpload控件上传文件
- 使用FileUpload上传控件上传文件
- ASP:FileUpload控件(文件上传控件)
- 文件上传有关问题(含代码)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- 设计模式-----桥接模式(Bridge Pattern)
- 关于按引用传递与按值传递
- java文件下载工具类
- Spring 之注解事务 @Transactional
- Eclipse 4.2 安装Java反编译插件
- FileUpload控件上传文件代码(含视频文件)
- 夏令营完成时是时前,侍
- 怎么样wi的地方器朋友乔
- Android自动化测试工具简介
- cmath库 与 贝塞尔函数Bessel
- 贪寄傻瀑貌勇谡松鲜敢欢谫壁锌迪
- 写给准备参加秋招的学弟学妹们~一定要来看哦~
- IOS开发的哪些异常之异常断点
- 《Advanced Windows Debugging》学习笔记