public static bool DeleteFile(int caseID, string fileName) { string fileDirectory = Configuration.GetKey("SiteDir") + "/Files/case/" + AdminTools.GetDirectotyID(caseID); string newfileName = fileDirectory + "/" + fileName; try { File.Delete(newfileName); return(true); } catch (Exception) { } return(false); }
public static bool UploadFile(int caseID, ref FileUpload CaseFile, out string newFileName) { if (CaseFile.HasFile) { // First Move to temp string destinationTempPath = Configuration.GetKey("SiteDir") + "/Files/case/temp/" + caseID.ToString() + "_" + CaseFile.FileName; if (File.Exists(destinationTempPath)) { File.Delete(destinationTempPath); } CaseFile.SaveAs(destinationTempPath); FileInfo fileInfo = new FileInfo(destinationTempPath); string extension = fileInfo.Extension; string destinationDir = Configuration.GetKey("SiteDir") + "/Files/case/" + AdminTools.GetDirectotyID(caseID); if (!Directory.Exists(destinationDir)) { Directory.CreateDirectory(destinationDir); } string destinationPath; newFileName = caseID.ToString() + extension; destinationPath = destinationDir + "/" + newFileName; if (File.Exists(destinationPath)) { File.Delete(destinationPath); } CaseFile.SaveAs(destinationPath); try { File.Delete(destinationTempPath); } catch (Exception) { } return(true); } else { newFileName = ""; return(false); } }