我上传了图片,但不能获得路径,在线等
protected void Button1_Click(object sender, EventArgs e)
{
bool fileIsValid = false;
//确认上传文件是否符合类型
if (this.FileUpload1.HasFile)
{
string FileExtension = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower();
string[] restrictEstension= { ".gif", ".jpg", ".bmp", ".png" };
//判断文件是否符合类型
for (int i = 0; i < restrictEstension.Length; i++)
{
if (FileExtension ==restrictEstension[i])
{
fileIsValid = true;
}
}
//r如果符合类型,调用SAVEAS进行上传
if (fileIsValid == true)
{
this.FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.FileName));
string flashpath = this.FileUpload1.PostedFile.FileName;
string flashtitle = TextBox1.Text.Trim();
string flashlink = TextBox2.Text.Trim();
bool b = new Flashmanager().insertflah(flashtitle, flashpath, flashlink);
if (b)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加成功");
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加失败");
}
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('双传不成功");
}
}
[解决办法]
string savePath = Server.MapPath(string.Format("~/images/{0}", FileUpload1.FileName));
bool b = new Flashmanager().insertflah(flashtitle, savePath, flashlink);