我要疯了~~~谁来救救我啊!?[没分了,只能用眼泪了]
HTML中这样写:
<body>
<form id=form1 runat=server>
<asp:Image ID= "Image1 " runat= "server " Style= "z-index: 100; left: 72px; position: absolute;
top: 33px " />
<input id= "File1 " runat= "server " style= "z-index: 102; left: 0px; position: absolute;
top: 0px " type= "file " />
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Style= "z-index: 103;
left: 156px; position: absolute; top: 31px " Text= "Button " Width= "58px " />
</form>
</body>
CS中这样写:
protected void Button1_Click(object sender, EventArgs e)
{
string fullFileName = this.File1.PostedFile.FileName;
string fileName = fullFileName.Substring(fullFileName.LastIndexOf( "\\ ") + 1);
string type = fullFileName.Substring(fileName.LastIndexOf( ". ") + 1);
if (type == "jpg " || type == "bmp " || type == "gif ")
{
this.File1.PostedFile.SaveAs(Server.MapPath( "up ") + "\\ " + fileName);
this.Image1.ImageUrl = "up " + fileName;
}
else
{
Response.Write( " <Scrip Language= 'javascript '> alert( 'error '); <Script> ");
}
}
这是一个图片的上传代码,图片上传的控件为HTML中的 "input(file) "控件,而且已经将其转化作为服务器控件运行了。另外Button1和Image1是VS2005工具箱标准栏里的那些,因为出现了一些如“
未将对象引用设置到对象的实例”这种错误,故已经把html中Button1和Image1的代码也移到了 <form> 中,这样那个“未将对象引用设置到对象的实例”的错误就没出现了。
但是在选好了图片的路径点按钮上传后则显示“alert( 'error ');”,图片没上传成功,这是怎么一回事,请高手指点迷津,亿万分感谢!
------解决方案--------------------pr