初学自定义控件,发现运行比较慢,求助!!

100c 2004-12-17 07:38:32
是一个上传文件的自定义控件
发现比正常的慢许多
求教各位高手

源程序如下:
<%@ Control Language="C#" ClassName="MyPostFile" %>

<script runat="server">

public string UpFileId;

void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["hifCount"] = 1;
}
else
{
for (int intCounter = 2; intCounter <= (int)ViewState["hifCount"]; intCounter++)
{
AddNewhif(intCounter.ToString());
}
}
}

void add_Click(object sender, EventArgs e)
{
ViewState["hifCount"] = (int)ViewState["hifCount"] + 1;
AddNewhif(ViewState["hifCount"].ToString());
}

void AddNewhif(string strhigNum)
{
Literal NewLiteral = new Literal();
NewLiteral.Text = "<br>";
plh1.Controls.Add(NewLiteral);

System.Web.UI.HtmlControls.HtmlInputFile hifNew = new HtmlInputFile();
hifNew.ID = "file" + strhigNum;
plh1.Controls.Add(hifNew);
}

void btnOk_Click(object sender, EventArgs e)
{
//得到File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile;
string fileName,filetype,NewfileName;
int intCount;
for (intCount = 0; intCount < files.Count; intCount++)
{
postedFile = files[intCount];
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName == "")
{
break;
}
}

for (int j = 0; j < intCount; j++)
{
postedFile = files[j];
//获得文件名字
fileName = System.IO.Path.GetFileName(postedFile.FileName);
filetype = System.IO.Path.GetExtension(fileName).ToLower();
UpFileId = DateTime.Now.ToString("s").Replace("-", "").Replace(":", "") + intCount.ToString();
NewfileName = UpFileId + j.ToString() + filetype;
if (fileName != "")
{
//可根据不同的扩展名字,保存文件到不同的文件夹
//注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("Uploads/") + NewfileName);
}
}
}
</script>
<asp:PlaceHolder ID="plh1" Runat="Server" /><br />
<input type="file" id="file1" runat="server" name="myfile1" />
<asp:Button ID="add" Runat="server" Text="添加" OnClick="add_Click" /><br />
<asp:Button ID="btnOk" Runat="Server" Text="确定" OnClick="btnOk_Click" />
...全文
160 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wula0010 2004-12-17
  • 打赏
  • 举报
回复
up

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧