public static bool ReplacePartFile(string partID, string filepath) { return(Website.WithDatabase((db) => { // Get previous filename string previous = db.QueryValue( "SELECT DigitalCopyPath FROM Parts WHERE ID=@0", partID) as string; // Change filename var count = db.Execute("UPDATE Parts SET DigitalCopyPath=@0 WHERE ID=@1", filepath, partID); if (count == 0) { return false; } // Now remove old file (if not the same as new one) if (!String.IsNullOrWhiteSpace(previous) && (String.IsNullOrWhiteSpace(filepath) || System.IO.Path.GetFullPath(previous) != System.IO.Path.GetFullPath(filepath))) { return Website.DeleteHiddenFile(previous); } return true; })); }