I have a user input as D:\Test1\Test2\Test3\Test4\a\b\c\d\file.jpg
as per the user input i need to check if folder and sub folder exist in a Document Library.
i.e
DocLib>>Test1>>Test2....d i want to replicate the folder structure in Document Library, if it exist than directly read and save the file else create directory and than subdirectory and upto the level wherin file should be saved.
Can anyone help me to understand how can i go with this? I tried with creating files in local system on hard drive
static void CopyFolder(string sourceFolder, string destFolder)
{
if (!Directory.Exists(sourceFolder))
Directory.CreateDirectory(destFolder);
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
File.Copy(file, dest);
}
//check folder in the source destination
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(destFolder, name);
System.IO.Directory.CreateDirectory(dest);
CopyFolder(folder, dest);
}
}
No idea how to check if directory exist and than check for subdirectory in sharepoint. i.e add a file by retaining the folder structure specified. Kindly help