please help me....
I want to copy all files from sharepoint document library to my local folder
here is mycode: I got an error message (value does not fall within the expecte range)
please help....
I don't know what to do next...
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class Program: MyClass
{
public static void Main(string[] args)
{
Console.WriteLine("please wait");
Console.ReadLine();
try
{
MyClass z = new MyClass();
z.DownloadDocumentsFromFolder(@"http://personal/administrator/b");
z.DownloadFileFromSharePointFolder(@"C:\mn");
}
catch (Exception Ex)
{
Console.Error.WriteLine(Ex.Message);
Console.Read();
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class MyClass
{
byte[] fileInfo;
string fileName;
public string DownloadDocumentsFromFolder(string spSiteUrl)
{
SPSite siteurl = new SPSite(@"http://personal/administrator/b/Forms/AllItems.aspx?RootFolder=%2fpersonal%");
SPWeb web = siteurl.OpenWeb();
SPFolder SelectedFolder = web.GetFolder((@"http://personal/administrator/b/") + "ann");
//if (SelectedFolder.SubFolders.Count > 0)
//{
foreach (SPFolder folderCollection in SelectedFolder.SubFolders)
{
if (folderCollection.Name == "ann")
{
SPFolder folderToDownload = web.GetFolder(folderCollection.Url);
for (int i = 0; i < folderToDownload.Files.Count; i++)
{
if (fileName == folderToDownload.Files.Folder.Name)
{
fileInfo = new byte[100];
fileInfo = DownloadFileFromSharePointFolder(folderToDownload.Files.Folder.Url);
}
}
}
}
// }
return Convert.ToString(fileInfo);
}
public byte[] DownloadFileFromSharePointFolder(string spFileURL)
{
SPSite site = new SPSite(@"http://personal/administrator/b/Forms/AllItems.aspx?RootFolder=%2fpersonal%");
SPWeb web = site.OpenWeb();
SPFile sourceFile = web.GetFile(@"C:\mn"); // the problem lies here, It stopped here and displayed the error
byte[] fileData = (byte[])sourceFile.OpenBinary();
Console.WriteLine(fileData);
return fileData;
Console.Read();
}
}
}