04
12
.net 使用FileUpLoad 控件上传大文件
作者:独木舟 日期:2008-04-12
///作用:FileUpLoad 上传大文件使用.net 的FileUpLoad 控件上传文件非常的方便, 在Web.config 中的<System.web>下添加如下的语句
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
评论: 5 | 引用: 0 | 查看次数: -
发表评论
速度可能跟网速有关,我本地上传很快。