Frage

How do I copy document library documents to local drive programmatically in Sharepoint 2007?

War es hilfreich?

Lösung

I'm not at my computer but something like this should do the trick.

using (SPSite site = new SPSite("http://sitecol"))
{
   SPWeb web = site.RootWeb;
   SPFolder docLib = web.GetFolder("DocLibName");

   foreach (SPFile f in docLib.Files)
   {
      // Use RWEP when accessing local file system
      SPSecurity.RunWithElevatedPrivileges(delegate(){
      {
         System.IO.File.WriteAllBytes(@"C:\Location\" + f.Name, f.OpenBinary());
      }
   }
}

Basically grab your site collection, then grab your spweb object, then grab your document library as a SPFolder. Then do a foreach loop through all the files in that folder, saving the byte array to your local filesystem.

Hope this helps!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top