日哦!有这么好谈论的啊!
用过时间服务器时间给图片名字 不就可以了吗?
protected void ButOK_Click(object sender, EventArgs e)
{
string namepic = "";
int types =int.Parse( this.drpPic.SelectedValue.ToString());
if (this.mypic.PostedFile.FileName.Trim() != "")
{
string type = Path.GetExtension(mypic.PostedFile.FileName.ToString()).ToLower();
if (".jpg".Equals(type) || ".gif".Equals(type))
{
if (this.mypic.PostedFile.ContentLength > 204800)
{
MessageBox.MessageBox.Show(this, "上传的图片内容太大!");
return;
}
else
{
namepic = DateTime.Now.ToString("yyyyMMddhhmmss") + type;
mypic.PostedFile.SaveAs(Server.MapPath("../img/" + namepic));
}
}
else
{
MessageBox.MessageBox.Show(this, "请上传JPG或GIF文件格式的图片!");
return;
}
}
StringBuilder sql = new StringBuilder();
sql.Append("insert into newspic (pic,picName,addtime,type)");
sql.Append("values(");
sql.Append("'" + this.txtText.Text.Trim() + "',");
sql.Append("'" + namepic + "',");
sql.Append("'" + DateTime.Now.ToString() + "',");
sql.Append("" + types + "");
sql.Append(")");
ProcessData.DefaultControl.Execute(sql.ToString());
MessageBox.MessageBox.Show(this, "图片上传成功!");
this.txtText.Text = "";
this.drpPic.SelectedIndex = 0;
return;
}