问题:我没有设置大小 上传了个9M的文件 就不行了。而且我调试的时候 都进不去 调试不了 为什么? //获取文件保存的路径
string FilePath = Server.MapPath(".//") + "Files";
//获取由客户端上载文件的控件集合
HttpFileCollection HFC = Request.Files;
for (int i = 0; i < HFC.Count; i++)
{
//对客户端已上载的单独文件的访问
HttpPostedFile UserHPF = HFC[i];
try
{
if (UserHPF.ContentLength > 0)
{ //调用GetAutoID方法获取上传文件自动编号
int IntFieldID = CC.GetAutoID("fileID", "tb_files");
//文件的真实名(格式:[文件编号]上传文件名)
//用于实现上传多个相同文件时,原有文件不被覆盖
string strFileTName = "[" + IntFieldID + "]" + System.IO.Path.GetFileName(UserHPF.FileName); string filename = System.IO.Path.GetFileName(UserHPF.FileName);//文件名字
string exec = filename.Substring(filename.LastIndexOf(".") + 1); //后最名 if (exec.ToLower() != "docx" && exec.ToLower() != "doc" && exec.ToLower() != "pdf")
{
ScriptManager.RegisterStartupScript(this, GetType(), "emptyError", "alert('只能上传(.docx .doc .pdf)三种类型!');", true);
return;
}
else
{
Tb_file useradd = new Tb_file();
useradd.FileID =int.Parse( IntFieldID.ToString());
useradd.FileName = System.IO.Path.GetFileName(UserHPF.FileName).ToString();
useradd.FileLoad = FilePath.ToString();
useradd.FileTrueName = strFileTName.ToString();
useradd.Areaname = buda.ToString();//省份
useradd.Cityname = TextBox1.Text.ToString();//单位名称
useradd.Tel = TextBox2.Text.ToString();//手机号码
useradd.Uname = TextBox3.Text.ToString();//姓名
useradd.Provincename = TextBox4.Text.ToString();//案例标题
useradd.Uptime = DateTime.Now.ToLongDateString();//系统默认时间 DateTime.Now.AddDays(-1)前一天
useradd.Unitname = ounameuser;//登陆人姓名
useradd.Verifying = "审核中";
Tb_fileManager.Instance.AddTb_file(useradd);
//将上传的文件存放在指定的文件夹中
UserHPF.SaveAs(FilePath + "//" + strFileTName);
IntIsUF = 1;
}
}
}
catch
{
//文件上传失败,清空缓存中的上传控件集,重新加载上传页面
if (Session["FilesControls"] != null)
{
Session.Remove("FilesControls");
}
Response.Write(CC.MessageBox("处理出错!", "FileUp.aspx"));
return;
} }
//当文件上传成功或者没有上传文件,都需要清空缓存中的上传控件集,重新加载上传页面
if (Session["FilesControls"] != null)
{
Session.Remove("FilesControls");
}
if (IntIsUF == 1)
{
IntIsUF = 0;
Response.Write(CC.MessageBox("上传成功!", "FileUp.aspx"));
}
else
{
Response.Write(CC.MessageBox("请选择上传文件!", "FileUp.aspx"));
}
string FilePath = Server.MapPath(".//") + "Files";
//获取由客户端上载文件的控件集合
HttpFileCollection HFC = Request.Files;
for (int i = 0; i < HFC.Count; i++)
{
//对客户端已上载的单独文件的访问
HttpPostedFile UserHPF = HFC[i];
try
{
if (UserHPF.ContentLength > 0)
{ //调用GetAutoID方法获取上传文件自动编号
int IntFieldID = CC.GetAutoID("fileID", "tb_files");
//文件的真实名(格式:[文件编号]上传文件名)
//用于实现上传多个相同文件时,原有文件不被覆盖
string strFileTName = "[" + IntFieldID + "]" + System.IO.Path.GetFileName(UserHPF.FileName); string filename = System.IO.Path.GetFileName(UserHPF.FileName);//文件名字
string exec = filename.Substring(filename.LastIndexOf(".") + 1); //后最名 if (exec.ToLower() != "docx" && exec.ToLower() != "doc" && exec.ToLower() != "pdf")
{
ScriptManager.RegisterStartupScript(this, GetType(), "emptyError", "alert('只能上传(.docx .doc .pdf)三种类型!');", true);
return;
}
else
{
Tb_file useradd = new Tb_file();
useradd.FileID =int.Parse( IntFieldID.ToString());
useradd.FileName = System.IO.Path.GetFileName(UserHPF.FileName).ToString();
useradd.FileLoad = FilePath.ToString();
useradd.FileTrueName = strFileTName.ToString();
useradd.Areaname = buda.ToString();//省份
useradd.Cityname = TextBox1.Text.ToString();//单位名称
useradd.Tel = TextBox2.Text.ToString();//手机号码
useradd.Uname = TextBox3.Text.ToString();//姓名
useradd.Provincename = TextBox4.Text.ToString();//案例标题
useradd.Uptime = DateTime.Now.ToLongDateString();//系统默认时间 DateTime.Now.AddDays(-1)前一天
useradd.Unitname = ounameuser;//登陆人姓名
useradd.Verifying = "审核中";
Tb_fileManager.Instance.AddTb_file(useradd);
//将上传的文件存放在指定的文件夹中
UserHPF.SaveAs(FilePath + "//" + strFileTName);
IntIsUF = 1;
}
}
}
catch
{
//文件上传失败,清空缓存中的上传控件集,重新加载上传页面
if (Session["FilesControls"] != null)
{
Session.Remove("FilesControls");
}
Response.Write(CC.MessageBox("处理出错!", "FileUp.aspx"));
return;
} }
//当文件上传成功或者没有上传文件,都需要清空缓存中的上传控件集,重新加载上传页面
if (Session["FilesControls"] != null)
{
Session.Remove("FilesControls");
}
if (IntIsUF == 1)
{
IntIsUF = 0;
Response.Write(CC.MessageBox("上传成功!", "FileUp.aspx"));
}
else
{
Response.Write(CC.MessageBox("请选择上传文件!", "FileUp.aspx"));
}
解决方案 »
- asp.net sql2005 做的多用户博客 日志是保存在数据库表中 还是用其他比如txt文本来保存呢?
- SQL主外键的问题
- 各位大哥帮我看看分页代码怎么改 谢谢
- BS项目中Server.Transfer如何在系统中传递变量值?
- [求助]水晶报表如何在交叉表根据汇总的值自定义显示?顶有分!
- 低分求难问题
- asp2.0 gridview绑定
- 555~~~穷死了,最后40分了,希望大家帮我看看,谢谢!
- 请问C#中获得字符的ASCII编码的函数是什么?根据编码获得字符的又是什么??
- ASP.NET MVC 如何实现 => 在网站中显示图片,但是不可以保存
- 内容页文章太长 如何在不影响html元素的情况下自动分页?
- 连接不到svn服务器,出现 200 OK,咋办?
在<system.web>节点中添加如下代码即可:
<httpRuntime maxRequestLength="2097151"/>
这个代码就是表示设置最大请求值,上传文件也就相当于请求。maxRequestLength单位为KB,最大值为:2097151.如果不设置,默认为4096 KB (4 MB)。
也就是说上传的文件最大可以上传2G以内的文件。
一般没有配置的话,默认只能上传4M以内的文件。配置了的话就可以上传更大的文件。