using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class 上传文件 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Visible = false;
}
protected void btn_Click(object sender, EventArgs e)
{
lblMessage.Visible = true;
string strPath = "";
strPath = Server.MapPath("~/file/"); try
{
if (this.upload.HasFile)
{
if (this.upload.PostedFile.ContentLength > 4194304)
{
this.lblMessage.Text = "对不起!上传文件的大小不能超过4MB";
return;
}
string strExtion = System.IO.Path.GetExtension(this.upload.FileName);
if (strExtion.ToLower() != ".mp3" && strExtion.ToLower() != ".wav")
{
this.lblMessage.Text = "对不起!只能上传.mp3或.wav的音频文件!";
this.upload.Focus();
return;
}
this.upload.PostedFile.SaveAs(strPath + this.upload.FileName);
this.lblMessage.Text = "恭喜!上传文件成功!";
}
else
{
this.lblMessage.Text = "请选择上传文件!";
return;
} }
catch
{
this.lblMessage.Text = "上传文件失败!";
return;
}
}
}请问这段代码中的 if (this.upload.PostedFile.ContentLength > 4194304)
{
this.lblMessage.Text = "对不起!上传文件的大小不能超过4MB";
return;
}
怎么不执行啊?谢谢!这段代码还有哪些问题啊?非常感谢!
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class 上传文件 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Visible = false;
}
protected void btn_Click(object sender, EventArgs e)
{
lblMessage.Visible = true;
string strPath = "";
strPath = Server.MapPath("~/file/"); try
{
if (this.upload.HasFile)
{
if (this.upload.PostedFile.ContentLength > 4194304)
{
this.lblMessage.Text = "对不起!上传文件的大小不能超过4MB";
return;
}
string strExtion = System.IO.Path.GetExtension(this.upload.FileName);
if (strExtion.ToLower() != ".mp3" && strExtion.ToLower() != ".wav")
{
this.lblMessage.Text = "对不起!只能上传.mp3或.wav的音频文件!";
this.upload.Focus();
return;
}
this.upload.PostedFile.SaveAs(strPath + this.upload.FileName);
this.lblMessage.Text = "恭喜!上传文件成功!";
}
else
{
this.lblMessage.Text = "请选择上传文件!";
return;
} }
catch
{
this.lblMessage.Text = "上传文件失败!";
return;
}
}
}请问这段代码中的 if (this.upload.PostedFile.ContentLength > 4194304)
{
this.lblMessage.Text = "对不起!上传文件的大小不能超过4MB";
return;
}
怎么不执行啊?谢谢!这段代码还有哪些问题啊?非常感谢!
if (this.upload.HasFile)
{}
这里面了吗?