图片上传
protected void btnUpload_Click(object sender, EventArgs e)
{
Button btnupload = sender as Button;
if (btnupload.ID.Equals("btnUpload"))//待补中的上传
{
if (!fuFileUp.HasFile)
{
//ScriptManager.RegisterClientScriptBlock(this.upAttachment, this.GetType(), "", "alert('请选择要上传的文件!')", true);
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请选择要上传的文件!')", true);
return;
}
}
string strUploadFile = ConfigHelper.GetConfigString("UploadFilePath");
string remoteFilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + strUploadFile.TrimEnd('\\') + "\\" +
"\\Approval\\";
if (!Directory.Exists(remoteFilePath))
{
Directory.CreateDirectory(remoteFilePath);
}
DataRow drNewRow = Attachment.NewRow();///加新行,都临时保存到viewState中
drNewRow["AttachmentID"] = Guid.NewGuid();
string strFileName = "";
string strOrgFileName = "";
strFileName = "/" + System.DateTime.Now.ToString("yyyyMMdd") + "_" + Guid.NewGuid() + Path.GetExtension(fuFileUp.FileName);
strOrgFileName = fuFileUp.FileName; //文件名
fuFileUp.PostedFile.SaveAs(remoteFilePath + strFileName);
string remoteFileName = "http://www.cnblogs.com/" + strUploadFile + "/Approval" + strFileName;//相对路径
drNewRow["ReferenceID"] = strInventoryID;
drNewRow["FileName"] = strOrgFileName;
drNewRow["FileType"] = strOrgFileName.Substring(strOrgFileName.LastIndexOf("."));
drNewRow["FileFullName"] = remoteFileName;
drNewRow["CreateBy"] = GetCurrentUser();
drNewRow["CreateDate"] = DateTime.Now.ToString();
drNewRow["ActiveFlag"] = (int)Common.CommonEnum.ActiveFlag.valid;
Attachment.Rows.Add(drNewRow.ItemArray);
LoadAttachment();
}
protected void rptAttachment_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
if (Attachment != null && Attachment.Rows.Count > 0)
{
DataRow[] drs = Attachment.Select("AttachmentID='" + e.CommandArgument.ToString() + "'");
if (drs.Length > 0)
{
drs[0]["ActiveFlag"] = (int)Common.CommonEnum.ActiveFlag.invalid;
drs[0]["ModifyBy"] = GetCurrentUser();
drs[0]["ModifyDate"] = DateTime.Now.ToString();
Attachment.AcceptChanges();
MessageBox.Show(this.Page, "删除成功!");
}
}
else
{
MessageBox.Show(this.Page, "删除失败!");
}
LoadAttachment();
}
}