public void MoveFileToPrintFolder(MoveFile moveFile) { //1. Move the file to the new folder //2 Insert record giving folder that and name of document moveFile.FileName = moveFile.FileName.Replace("\n", ""); moveFile.FilePath = moveFile.FilePath.Replace("\n", ""); moveFile.Folder = moveFile.Folder.Replace("\n", ""); try { moveFile.ID = GetMoveFileId(moveFile.Folder, Utility.GetUserName(), moveFile.DocumentType); File.Move(moveFile.FilePath, System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" + moveFile.FileNewName); moveFile.FilePath = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" + moveFile.FileNewName; System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName()); AddFileToFolder(moveFile); string s2 = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + "\\" + moveFile.FileName; Logging.LogErrors(ConfigurationValues.ErrorLogPath, "File successfully moved"); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); } }
public bool AddFileToFolder(MoveFile moveFile) { using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection)) { try { const string query = "INSERT INTO [HoldFiles]" + " (" + " [HoldFolderID]" + " ,[ActiveDirectoyUser]" + " ,[FolderName]" + " ,[FileName]" + " ,[FilePath]" + " ,[DocumentType]" + ")" + " VALUES" + "(" + " @HoldFolderID,@ActiveDirectoyUser,@FolderName,@FileName,@FilePath,@DocumentType" + " )"; int rowsAffectd = db.Execute(query, new { @HoldFolderID = moveFile.ID, @ActiveDirectoyUser = Utility.GetUserName(), @FolderName = moveFile.Folder, @FileName = moveFile.FileNewName, @FilePath = moveFile.FilePath, @DocumentType = moveFile.DocumentType }); return true; } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); return false; } } }
public void MoveFileToFolder(MoveFile moveFile) { //1. Move the file to the new folder //2 Insert record giving folder that and name of document moveFile.FileName = moveFile.FileName.Replace("\n",""); moveFile.FilePath = moveFile.FilePath.Replace("\n", ""); moveFile.Folder = moveFile.Folder.Replace("\n", ""); List<InBoundFaxes> inBoundFaxesList = new List<InBoundFaxes>(); List<OutboundFaxDocument> outboundFaxDocumentList = new List<OutboundFaxDocument>(); string name = string.Empty; try { using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection)) { const string query = "SELECT PostOfficeFoldersByUser.ActiveDirectoyUser," + " PostOfficeFoldersByUser.Path,PostOfficeFoldersByUser.Name" + " FROM [PostOfficeFoldersByUser]" //+ " INNER JOIN HoldFolders" //+ " ON HoldFolders.ActiveDirectoyUser = PostOfficeFoldersByUser.ActiveDirectoyUser" + " where PostOfficeFoldersByUser.ActiveDirectoyUser = @ActiveDirectoyUser"; inBoundFaxesList = db.Query<InBoundFaxes>(query, new { @ActiveDirectoyUser = Utility.GetUserName() }).ToList(); for (int i = 0; i < inBoundFaxesList.Count; i++) { OutboundFaxDocument outboundFaxDocument = new OutboundFaxDocument(); string[] filePaths = Directory.GetFiles(inBoundFaxesList[i].Path); if (filePaths.Length > 0) { for (int j = 0; j < filePaths.Length; j++) { string[] fileName = filePaths[j].Split('\\'); if (moveFile.FileName == fileName[fileName.Length - 1]) { try { moveFile.ID = GetMoveFileId(moveFile.Folder, Utility.GetUserName(), moveFile.DocumentType); moveFile.FilePath = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" + moveFile.FileNewName; System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName()); AddFileToFolder(moveFile); string s2 = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + "\\" + moveFile.FileName; //moveFile.FileName = moveFile.FileName.Replace(" ", "_"); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Moving file from " + filePaths[j] + " to " + System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + "\\" + moveFile.FileName); File.Move(filePaths[j], moveFile.FilePath); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "File successfully moved"); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); } } } } } } } catch (Exception er) { string s1 = er.ToString(); //return outboundFaxDocumentList; } }