Welcome to Office & SharePoint Pro Sign in | Join | Help

SUBSCRIBE to Windows IT Pro Magazine & SAVE 30%      FREE Email Newsletters Vista UPDATE, Windows IT Pro UPDATE & More

please help..how to copy all files from sharepoint to local folder

  •  11-03-2007, 8:56 PM

    please help..how to copy all files from sharepoint to local folder

    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();

               

            }
        }
    }

     

View Complete Thread
SPONSORED LINKS FEATURED LINKS

SharePoint Security SimplifiedHaving trouble with Permissions in your SharePoint environment? Check out USPM v2007® Order Your Fundamentals CD Today!Get up to speed quickly and learn how to uncover rich information management and deployment capabilities with this free SharePoint CD. Simplify Content Migration for SharePointEase the job of SharePoint migration and ongoing site maintenance. Michael Noel outlines your migration options in this white paper. Download today! Prepare Yourself for Exchange CatastropheRead this white paper to learn how you can keep Exchange server healthy, as well as predict and respond to server failure. Featured eBook - Fundamentals of Fax Server TechnologyTake advantage of the benefits of fax servers and find out how you can implement a solution that is easy to support, secure, and integrate. Dramatically Accelerate Microsoft SharePointDeliver unimpeded access to SharePoint - Learn how to fix more than just the symptoms of slow application delivery and poor performance. Protect Your Company’s Digital AssetsDo you know the risks of sending important files over email or FTP? Read this white paper to learn what you can do to safeguard your company’s data. Boost Customer Confidence and SatisfactionRead this eBook to learn how fax servers can ease communication with less computer-savvy customers while reducing your security, compliance, and support woes. Implement a Successful Archiving SolutionView this web seminar to learn the best practices for creating an email archive that is secure, compliant, and searchable.