图片上传问题
protected void Button1_Click(object sender, EventArgs e) {
string fullname = this.FileUpload1.FileName.ToString();
string fn = System.DateTime.Now.ToString("yyyyMMddHHmmss") + fullname;
string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1);
string size = this.FileUpload1.PostedFile.ContentLength.ToString();
if (typ2 == "gif" ? ? typ2 == "jpg" ? ? typ2 == "bmp" ? ? typ2 == "png")
{
this.FileUpload1.SaveAs(Server.MapPath("../upimage") + "\\" + fn);
this.Image1.Visible = true;
this.Image1.ImageUrl = "../upimage/" + fn;
OleDbConnection conn = new OleDbConnection(ConfigurationManager.AppSettings["mdb"]);
OleDbCommand insert = new OleDbCommand("insert into photo (fenlei,biaoti,url,pho,addtime) values ('" + this.DropDownList1.SelectedValue + "','" + this.TextBox1.Text.ToString() + "','" + this.TextBox2.Text.Trim() + "','" + fn + "','" + System.DateTime.Now + "')", conn);
conn.Open();
insert.ExecuteReader();
conn.Close();
Label1.Text = "上传成功" + fn;
}
else
{
Label1.Text = "文件类型不支持,只能上传 .jpg .gif .bmp .png 格式的图片";
}
}
现在出现问题,iis不设置虚拟目录的时候,上传正常。
只要一设置虚拟目录,上传的时候,就弹出对话框提示 “未将对象引用设置到对象的实例”
请高手帮忙。