/// <summary> /// Moves specified video to specified location. /// </summary> /// <param name="item">The video to move.</param> /// <param name="destination">The destination to move the file to.</param> /// <returns>True if the move was successful, otherwise False.</returns> public bool MoveFile(Media item, string destination) { MoveFileItem FileInfo = new MoveFileItem() { VideoId = item.MediaId, FileName = item.FileName, NewFileName = destination }; return MoveFile(FileInfo, false); }
/// <summary> /// Moves specified video to specified location. /// </summary> /// <param name="item">The information about the move.</param> /// <param name="save">Whether to save changes to the database.</param> /// <returns>True if the move was successful, otherwise False.</returns> public bool MoveFile(MoveFileItem item, bool save) { try { Directory.CreateDirectory(Path.GetDirectoryName(Settings.NaturalGroundingFolder + item.NewFileName)); File.Move(Settings.NaturalGroundingFolder + item.FileName, Settings.NaturalGroundingFolder + item.NewFileName); if (save) { EditVideoBusiness Business = new EditVideoBusiness(); Media EditVideo = Business.GetVideoById(item.VideoId); EditVideo.FileName = item.NewFileName; Business.Save(); } // Delete source folder if empty. string SourceDirectory = Path.GetDirectoryName(Settings.NaturalGroundingFolder + item.FileName); if (!Directory.EnumerateFileSystemEntries(SourceDirectory).Any()) Directory.Delete(SourceDirectory); return true; } catch { return false; } }