真郁闷!上传图片的奇怪问题!请高手帮帮忙!在线等!急!!!!
我的代码如下:
<body MS_POSITIONING="GridLayout">
<form id="AddandShowImage" method="post" runat="server">
<INPUT id="FileUp" style="Z-INDEX: 101; LEFT: 77px; POSITION: absolute; TOP: 97px" type="file" runat="server" name="file">
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 77px; POSITION: absolute; TOP: 149px" runat="server" Height="21px" Text="上传"></asp:button><asp:image id="Image1" style="Z-INDEX: 103; LEFT: 79px; POSITION: absolute; TOP: 179px" runat="server" Height="123px" Width="99px"></asp:image><asp:button id="Button2" style="Z-INDEX: 104; LEFT: 202px; POSITION: absolute; TOP: 182px" runat="server" Height="20px" Text="浏揽图片" Width="86px"></asp:button><asp:label id="Label1" style="Z-INDEX: 105; LEFT: 78px; POSITION: absolute; TOP: 64px" runat="server" Width="258px" Visible="False">必须上传后缀名为.jpg或.gif的文件!!</asp:label>
<asp:Label id="fname" style="Z-INDEX: 106; LEFT: 79px; POSITION: absolute; TOP: 125px" runat="server" Font-Size="Smaller"></asp:Label></form>
</body>
=========================================================================
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Visible =false;
HttpPostedFile UpFile=FileUp.PostedFile;
//判断文件是否大于120K
long asq=122988;
if(Convert.ToInt64(this.FileUp.PostedFile.ContentLength) > asq)
{
Label1.Visible =true;
Label1.Text="[上传的文件太大,最大支持120K!]";
}
//判断文件是否为空
else if(Convert.ToInt64(FileUp.PostedFile.ContentLength)==0)
{
Label1.Visible =true;
Label1.Text="[不能上传空文件!]";
}
else
{
//得到上传文件的后缀名
string fileExt = (System.IO.Path.GetExtension(UpFile.FileName)).ToString().ToLower();
if(fileExt == ".jpg"||fileExt == ".gif" )
{
int k=Convert.ToInt32(Session["id"].ToString());
long CurrentLength = Convert.ToInt64( FileUp.PostedFile.ContentLength );
fname.Text = "您上传的图片路径为: "+UpFile.FileName+". 请点击左下方的 '简历预览' 按钮查看您的照片:";
string fileName=moudel.Enter.getImageAddress(UpFile.FileName);//得到修改后缀名的上传文件名
fileName=Session["name"].ToString() + fileName;
//把上传的图片文件存储到相对路径下
UpFile.SaveAs(moudel.Enter.getPhysicalPath(Request.PhysicalPath)+"\\image\\" + fileName);
// ds_person.get_ImageAddress=fileName.ToString();
// ds_person.SB_ImageAddressUpdate();
}
else
{
Label1.Visible =true;
}
}
}
结果报以下错误:
将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 58: long asq=122988;
行 59:
行 60: if(Convert.ToInt64(this.FileUp.PostedFile.ContentLength) > asq)//错在这
行 61:
行 62: {
源文件: f:\inetpub\wwwroot\webapplicationdatelist\addandshowimage.aspx.cs 行: 60