上传
//判断是否为合格上传格式
public bool ifisfile(string str)
{
bool file0k = false;
string[] allowedextensions ={ ".pdf",".ppt", ".doc", ".xls", ".png", ".jpg", ".png", ".bmp", ".txt", ".pdg",".rar",".zip", ".gif" };
for (int i = 0; i < allowedextensions.Length; i++)
{
if (str == allowedextensions[i])
{
file0k = true;
break;
}
}
if (file0k)
return true;
else
return false;
}
//上传函数
public void upload()
{
string fileextension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
if (ifisfile(fileextension))
{
string fname = FileUpload1.FileName;
string ftype = System.IO.Path.GetExtension(FileUpload1.FileName);
attach = createstring() + fname;
FileUpload1.SaveAs(Server.MapPath("~\\upload") + "\\" +attach);
}
else
{
WebMessageBox.Show("上传文件格式不对!");
return;
}
}
//上传
protected void btnadd_Click(object sender, EventArgs e)
{
string title = txttitle.Text;
string summary = txtsummary.Text;
string content = txtContent.Value;//FCKeditor1.Value;
string remark = txtremark.Text;
int tid = Convert.ToInt32(ViewState["tid"].ToString());
string esid="";
attach = FileUpload1.FileName.ToString();
if (attach.Length>1)
{
upload();
}
if (ViewState["esid"]!=null)
{
esid = ViewState["esid"].ToString();
}
else
{
esid = createstring();
}
if (article.articlecreate(tid, esid, title, summary, content, remark, attach))
{
WebMessageBox.Show("Add success!");
}
else
WebMessageBox.Show("Add failed");
}

浙公网安备 33010602011771号