public static string RecurseThroughDirectory(DirectoryInfo dir, int folderId, int UserModuleID, ref StringBuilder sb) { foreach (FileInfo file in dir.GetFiles()) { ATTFile obj = new ATTFile(); obj.PortalId = fb.GetPortalID; obj.UniqueId = Guid.NewGuid(); obj.VersionGuid = Guid.NewGuid(); obj.FileName = file.Name; obj.Extension = file.Extension; obj.Size = int.Parse(file.Length.ToString()); obj.ContentType = FileManagerHelper.ReturnExtension(file.Extension); obj.Folder = FileManagerHelper.ReplaceBackSlash(dir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, "")); obj.FolderId = folderId; obj.IsActive = 1; obj.StorageLocation = 0; obj.AddedBy = fb.GetUsername; try { if (FileManagerHelper.CheckForValidExtensions(UserModuleID, file.Extension.Replace(".", ""), fb.GetPortalID)) { FileManagerController.AddFile(obj); sb.Append("File ").Append("Extraction completed successfully"); } else { sb.Append("File ").Append(file.Name).Append(" has invalid extension \n"); } } catch (Exception ex) { fb.ProcessException(ex); } } foreach (DirectoryInfo childDir in dir.GetDirectories()) { Folder folder = new Folder(); folder.PortalId = fb.GetPortalID; folder.ParentID = folderId; folder.FolderPath = FileManagerHelper.ReplaceBackSlash(childDir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, "")); folder.StorageLocation = 0; folder.UniqueId = Guid.NewGuid(); folder.VersionGuid = Guid.NewGuid(); folder.IsActive = 1; folder.IsRoot = false; folder.AddedBy = fb.GetUsername; try { int FolderID = FileManagerController.AddFolderReturnFolderID(folder); RecurseThroughDirectory(childDir, FolderID, UserModuleID, ref sb); } catch (Exception ex) { fb.ProcessException(ex); } } return(sb.ToString()); }
public void AddFileToDatabase(string fileName, string extension, string folder, int folderId, bool isDatabase, int saveMode) { string newFileName = fileName; if (saveMode == 1) { newFileName = fileName + ".resources"; } FileInfo file = new FileInfo(GetAbsolutePath(folder + newFileName)); ATTFile obj = new ATTFile(); obj.PortalId = fb.GetPortalID; obj.UniqueId = Guid.NewGuid(); obj.VersionGuid = Guid.NewGuid(); obj.FileName = fileName; obj.Extension = extension; obj.Size = int.Parse(file.Length.ToString()); obj.ContentType = FileManagerHelper.ReturnExtension(extension); obj.Folder = folder; obj.FolderId = folderId; obj.IsActive = 1; obj.StorageLocation = saveMode; obj.AddedBy = fb.GetUsername; if (isDatabase) { byte[] _fileContent = FileManagerHelper.FileToByteArray(GetAbsolutePath(folder + fileName)); obj.Content = _fileContent; } try { FileManagerController.AddFile(obj); if (saveMode == 2) { file.Delete(); } } catch (Exception ex) { fb.ProcessException(ex); } }