public void deleteFile(HttpContext _context, AccessLayer.FileAccess myAccess) { int fileID = Convert.ToInt32(_context.Request.Params["fileID"]); string path = myAccess.getFilePath(fileID); try { System.IO.File.Delete(_context.Server.MapPath(path)); myAccess.deleteTaskFile(fileID, Convert.ToInt32(_context.Session["userID"])); } catch (Exception) { }; }
public string uploadFile(HttpContext _context, AccessLayer.FileAccess myAccess, int projectID) { // Upload file var uploadFile = _context.Request.Files[0]; string name = getFileName(uploadFile.FileName); string path = "/Uploads/Project_" + projectID.ToString() + "/" + name; var filePath = _context.Server.MapPath(path); try { uploadFile.SaveAs(filePath); } catch (Exception) { } var param = _context.Request.Params; // Create new file object and save info of uploaded file to database FileModel file = new FileModel(); file.Task_ID = Convert.ToInt32(param["taskID"]); file.User_ID = Convert.ToInt32(_context.Session["UserID"]); file.Name = name; file.Type = getFileType(param["fileType"], name); file.Path = path; return(myAccess.linkTaskFile(file)); }