按钮里面protected void Button2_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.PostedFile.FileName != "")
{
string ImgPath = FileUpload1.PostedFile.FileName;
string ImgName = ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1);
string ImgExtend = ImgPath.Substring(ImgPath.LastIndexOf(".") + 1);
if (!(ImgExtend == "xls" || ImgExtend == "XLS" || ImgExtend == "DOC" || ImgExtend == "doc" || ImgExtend == "txt" || ImgExtend == "TXT" || ImgExtend == "rar" || ImgExtend == "RAR"))
{
Label1.Text = "上传文件的格式不正确!";
return;
}
string ServerPath = Server.MapPath("excel/") + ImgName;
FileUpload1.PostedFile.SaveAs(ServerPath);
SqlConnection oc = new SqlConnection(ConfigurationManager.AppSettings["long"]);
oc.Open();
string ACE = "insert into [tongbao] (leixingID,neirong,biaoti,biaoge,fabiaoren)" + " values( '" + id + "', '" + FCKeditor1.Value.ToString() + "', '" + TextBox1.Text.Trim() + "','" + ImgName + "','"+mokuai.Text+"')";
SqlCommand shi = new SqlCommand(ACE, oc);
shi.ExecuteNonQuery();
oc.Close();
Response.Write("<script language=javascript>alert('添加成功!')</script>");
}
}
catch
{
Response.Write("<script language=javascript>alert('添加错误!')</script>");
}