private void LoadSubDirs(string directory, int PresentFolderid, int Rootid) { FileInformation Sub = new FileInformation(); SubFoldersPath.Add(directory); string[] SubdirectoryEntries = Directory.GetDirectories(directory); //Identifying and retriving the all sub folders string[] AllFilesinDirectory = Directory.GetFiles(directory); //Identifying and retriving the all sub files foreach (String FilePath in AllFilesinDirectory) // we have all file now getting file info and upload it into database { try { DAL.Model.FileInfo fileInfo = GetFileInfo(FilePath); //getting File info Sub.UploadFile(fileInfo, PresentFolderid); //upload into database } catch (Exception Ex) { ErrrorLog.ErrorlogWrite(Ex); } } foreach (string subdirectory in SubdirectoryEntries) //all subfolders { try { SubFolder FolderDetails = GetFolderdetails(subdirectory); //getting sub folder details int FolderID = Sub.UploadSubFolder(FolderDetails, Rootid); //upload the sub folder into datatbase and that return id after insert LoadSubDirs(subdirectory, FolderID, Rootid); //the id is used for uploading file } catch (Exception Ex) { ErrrorLog.ErrorlogWrite(Ex); } } }
IList <string> SubFoldersPath = new List <string>(); // list for SubFoldersPath public void GetSubDirectories(String RootFolderPath, int RootFolderId) //It contains the sub folders and files { FileInformation Dbcall = new FileInformation(); string[] SubdirectoryEntries = Directory.GetDirectories(RootFolderPath); //Identifying and retriving the all sub folders string[] AllFilesinDirectory = Directory.GetFiles(RootFolderPath); //Identifying and retriving the all sub files if (AllFilesinDirectory.Length > 0) //checking the root folders is contains the files or not { SubFoldersPath.Add(RootFolderPath); SubFolder FolderDetails = GetFolderdetails(RootFolderPath); //Retriving the folder information int PresentFolderID = Dbcall.UploadSubFolder(FolderDetails, RootFolderId); //upload into the database foreach (String FilePath in AllFilesinDirectory) { try { DAL.Model.FileInfo FileInfo = GetFileInfo(FilePath); //Retriving the file information Dbcall.UploadFile(FileInfo, PresentFolderID); //upload into the database } catch (Exception ex) { ErrrorLog.ErrorlogWrite(ex); } } } foreach (string subdirectory in SubdirectoryEntries) { try { SubFolder FolderDetails = GetFolderdetails(subdirectory); int FolderID = Dbcall.UploadSubFolder(FolderDetails, RootFolderId); //upload into the database LoadSubDirs(subdirectory, FolderID, RootFolderId); //the sub folder is contains sub folder so call sub directory } catch (Exception Ex) { ErrrorLog.ErrorlogWrite(Ex); } } }