I am developing a console application which will get all the files in a document library and copy it to a particular location on system. I was successful in retrieving all the files within the library. However , i am unable to retain the folder structure. Files in diff folder are place in the library without the original structure i.e all in one place. Below is the code:
if ((list.GetType().ToString()=="Microsoft.SharePoint.SPDocumentLibrary") && !list.Hidden)
{
var Listdir = Sitedir+@"\"+list.Title.ToString();
if (!Directory.Exists(Listdir))
Directory.CreateDirectory(Listdir);
Console.WriteLine(list.Title);
foreach (SPListItem item in list.Items)
{
byte[] binFile = item.File.OpenBinary();
System.IO.FileStream fstream =
System.IO.File.Create(Listdir+"\\" + item.File.Name);
fstream.Write(binFile, 0, binFile.Length);
Console.WriteLine(item.File.Name);
}
}
Is there any way to retain folder structure?
Thanks