文档库文件夹从一个网站集转移到另一个网站集

时间:2010-12-21 11:48:34

标签: sharepoint sharepoint-2007

我想将文档库下的文件夹从一个网站集转移到其他网站集。请帮帮我!

2 个答案:

答案 0 :(得分:1)

以资源管理器模式打开文档库从一个位置复制它,在资源管理器视图中打开其他库将其粘贴到它们上面。

答案 1 :(得分:1)

如果您需要以通用方式以编程方式执行此操作,则可以使用将文件夹(或整个文档库)的内容写入文件系统的函数以及将其导入任何其他文档库的其他函数。

要导出:

void ExtractFolder(SPFolder spFolder, String systemFolder)
{
     String destinationFolder = Path.Combine(systemFolder, spFolder.Name);

     Directory.CreateDirectory(destinationFolder);

     foreach (SPFile file in spFolder.Files)
     {
         String fileLocation = Path.Combine(destinationFolder, file.Name);
         byte[] binaryFile = file.OpenBinary();

         using (FileStream fs = new FileStream(fileLocation, FileMode.OpenOrCreate, FileAccess.Write))
          {
                    fs.Write(binaryFile, 0, binaryFile.Length);
                    fs.Close();
          }
      }
      foreach (SPFolder subfolder in spFolder.SubFolders)
      {
          ExtractFolder(subfolder, destinationFolder);
      }
  }  

要导入:

void ImportListFromFolder(SPFolder spFolder, String systemFolder)
{
    ImportFilesToFolder(spFolder, systemFolder);

    DirectoryInfo directoryInfo = new DirectoryInfo(systemFolder);

    foreach (DirectoryInfo subDirectory in directoryInfo.GetDirectories())
    {
        SPFolder subfolder = spFolder.SubFolders.Add(subDirectory.Name);
        ImportListFromFolder(subfolder, subDirectory.FullName);
    }
}

void ImportFilesToFolder(SPFolder spFolder, string systemFolder)
{
     String fileMask = "*.*";

     DirectoryInfo directoryInfo = new DirectoryInfo(systemFolder);

     foreach (FileInfo fileInfo in directoryInfo.GetFiles(fileMask))
     {
            byte[] buffer = new byte[fileInfo.Length];
            using (FileStream fs = new FileStream(fileInfo.FullName, System.IO.FileMode.Open))
            {
                fs.Read(buffer, 0, (int)fileInfo.Length);
                fs.Close();
            }

            SPFile addedFile = spFolder.Files.Add(fileInfo.Name, buffer, false);

        }
    }