我寫了這個:ASP.net上傳文件,重命名,如果存在
protected void btnup_Click(object sender, EventArgs e)
{
if (ASPxUploadControl1.HasFile)
{
try
{
string filename = Path.GetFileName(ASPxUploadControl1.FileName);
ASPxUploadControl1.SaveAs(Server.MapPath("upload/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
問題是,如果我已經有File1.jpg,它將如果有人上傳File1.jpg覆蓋它。
在這裏做什麼?
什麼是真正的問題?你可以檢查FileExist嗎?首先或者你不能連接用戶與文件? – Aristos 2012-01-12 11:39:58