I was asked to copy a local 1TB folder worth of data to a Laserfiche repository using a C# tool. Usually to copy a folder tree I use this great method.
I am enumerating the local folder using this method, in order to ONLY get the folder and its tree.
IEnumerable<string> AllFolders2(string root)
{
var folders = Directory.EnumerateDirectories(root, "*", SearchOption.AllDirectories).Select(path => path.Replace(root, ""));
var listOfFiles = folders.ToList();
return listOfFiles;
}
My problem is the Laserfiche SDK that I am allowed to work with. I the linked method it uses Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath)); but the SDK is giving me a method called
void Create(string Name, LFFolder ParentFolder, bool AutoRename); that requires the parent folder too.
I've created this method to create a folder
void CreateFolder(string FolderName, string ParentPath)
{
try
{
lfParentFolder = (LFFolder)lfDB.GetEntryByPath(ParentPath);
lfFolder = new LFFolder();
try
{
lfFolder = (LFFolder)lfDB.GetEntryByPath(string.Format(@"{0}\\{1}", lfParentFolder.FullPath, FolderName));
}
catch (COMException ex)
{
if (ex.ErrorCode == -1073470679)
{
lfFolder.Create(FolderName, lfParentFolder, false);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
I'm stuck with getting the parent folders for the deeper levels. The SDK is 8.1 Any ideas?
You need to recursively go through each directory instead of using SearchOption.AllDirectories. Here is an example of recursively going through folders. The code crates an XML file of all files in a folder (and child folders).