做批量文件上传时,如我同时上传4个文件:
1.gif
2.gif
3.gif
4.gif
结果保存为:
1.gif
4.gif
4.gif
4.gif
也就是中间的2、3都没保存,为什么,怀疑与缓存有关,我又做了清除缓存的操作:
<META http-equiv="Pragma" content="no-cache">
结果又变成了全是4.gif
清除缓存用了很多方法,结果都差不多。要么保存首尾两张,要么全部是最后一张。主要代码如下:
HttpFileCollection files =Request.Files;for(iFile = 0;iFile<=files.Count-1;iFile++)
{
HttpPostedFile postedFile = files[iFile];
fileName =Path.GetFileName(postedFile.FileName);
Response.Write(fileName);
//省去一些没用代码
upimage.Save(newpath,GetImageType(postedFile.ContentType));//保存原始图片
thumimg.Save(thumpath,GetImageType(postedFile.ContentType)); //保存缩略图 //写数据库缩略图文件名
insert into tbimg(imgname)values(thumimg);//把缩略图文件名写进数据库}我Response.write出来的文件名还是1.gif,2.gif,3.gif,4.gif
数据库里保存的全是4.gif
到底为什么,搞了一天也没结果。
但如果我在Debug状态运行,则一切正常。===========================================================
哪位兄弟帮看看,不胜感激!!!!!!!!!!!!!!!
1.gif
2.gif
3.gif
4.gif
结果保存为:
1.gif
4.gif
4.gif
4.gif
也就是中间的2、3都没保存,为什么,怀疑与缓存有关,我又做了清除缓存的操作:
<META http-equiv="Pragma" content="no-cache">
结果又变成了全是4.gif
清除缓存用了很多方法,结果都差不多。要么保存首尾两张,要么全部是最后一张。主要代码如下:
HttpFileCollection files =Request.Files;for(iFile = 0;iFile<=files.Count-1;iFile++)
{
HttpPostedFile postedFile = files[iFile];
fileName =Path.GetFileName(postedFile.FileName);
Response.Write(fileName);
//省去一些没用代码
upimage.Save(newpath,GetImageType(postedFile.ContentType));//保存原始图片
thumimg.Save(thumpath,GetImageType(postedFile.ContentType)); //保存缩略图 //写数据库缩略图文件名
insert into tbimg(imgname)values(thumimg);//把缩略图文件名写进数据库}我Response.write出来的文件名还是1.gif,2.gif,3.gif,4.gif
数据库里保存的全是4.gif
到底为什么,搞了一天也没结果。
但如果我在Debug状态运行,则一切正常。===========================================================
哪位兄弟帮看看,不胜感激!!!!!!!!!!!!!!!
解决方案 »
- 做asp.net三层 sql语句太多 有什么办法?
- 为什么会定位到/admin/Default.aspx?
- gridview 分页
- DIV大小改变???
- RadioButtonList中的文字样式问题
- (CheckBoxList)FormView1.FindControl("AssetCollect");找不到指定的CheckBoxList控件。
- iis6.0 中后缀名为.bak 的文件 不能下载
- DropDownList怎么取不到数据呢?
- 【紧急】访问某一网站时,如何得到它首页自动生成的 uid 表单值?(uid类型为hidden)
- web用户控件和web自定义控件有什么区别?
- 最简单得问题,表得基本知识讨论! ----在线
- Context=“mix/Munlit"有什么用,用jmail发邮件跟他有什么关系?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>upMoreFile</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="JavaScript">
function addFileControl()
{
var str = '<INPUT type="file" NAME="File">'
document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="upMoreFile" method="post" encType="multipart/form-data" runat="server">
<asp:label id="Title" Runat="server"></asp:label>
<P id="FileCollection"><INPUT type="file" name="File">
</P>
<P><input onclick="addFileControl()" type="button" value="增加(File)">
<asp:button id="Upload" Runat="server" Text="上传" Width="56px"></asp:button><input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置">
</P>
<P align="center"><asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px"
Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label></P>
</form>
</body>
</HTML>
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace CommonFunction
{
/// <summary>
/// upMoreFile 的摘要说明。
/// </summary>
public class upMoreFile : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.WebControls.Label Title;
protected System.Web.UI.WebControls.Label strStatus;
private void Page_Load(object sender, System.EventArgs e)
{
Title.Text = "<h3>多文件上传</h3>";
Upload.Text = "开始上传";
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Upload.Click += new System.EventHandler(this.Upload_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Upload_Click(object sender, System.EventArgs e)
{
upMorefile();
} private bool upMorefile()
{
//遍历File表单元素
System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
//状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
int fileCount;
int filecount = files.Count;
try
{
for(fileCount = 0;fileCount<files.Count;fileCount++)
{
//定义访问客户端上传文件的对象
System.Web.HttpPostedFile postedFile = files[fileCount];
string fileName, fileExtension;
//取得上传得文件名
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if(fileName != String.Empty)
{
//取得文件的扩展名
fileExtension = System.IO.Path.GetExtension(fileName);
//上传的文件信息
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");
//保存到指定的文件夹
postedFile.SaveAs(Server.MapPath("upedFile/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception error)
{
strStatus.Text = error.Message;
return false; }
}
}
}