/// <summary> /// Deletes the file binary from the file system. /// </summary> /// <param name="attachmentId">Attachment ID</param> /// <param name="name">Returning the attachment name</param> protected bool DeleteFromFileSystem(int attachmentId, ref string name) { // Delete the file in file system AttachmentInfo ai = AttachmentInfoProvider.GetAttachmentInfo(attachmentId, false); if (ai != null) { name = ai.AttachmentName; // Ensure the binary column first (check if exists) DataSet ds = AttachmentInfoProvider.GetAttachments("AttachmentID = " + attachmentId, null, true, 0, "CASE WHEN AttachmentBinary IS NULL THEN 0 ELSE 1 END AS HasBinary"); if (!DataHelper.DataSourceIsEmpty(ds)) { bool hasBinary = ValidationHelper.GetBoolean(ds.Tables[0].Rows[0][0], false); if (!hasBinary) { // Copy the binary data to database ai.AttachmentBinary = AttachmentInfoProvider.GetFile(ai, GetSiteName(ai.AttachmentSiteID)); ai.Generalized.UpdateData(); } // Delete the file from the disk AttachmentInfoProvider.DeleteFile(ai.AttachmentGUID, GetSiteName(ai.AttachmentSiteID), true, false); return(true); } } return(false); }