我可以下载整个SPSite或SPWeb到硬盘(ATM我只能下载一个文件夹)



我制作了一个windows窗体应用程序,该应用程序以树视图的形式映射整个站点(在文本框中给出),但我想知道用户是否选择下载整个站点,我需要什么代码,我查看了谷歌,但找到了下载下面给出的一个文件或文件夹的代码,

下载文件夹

private void bFolder_Click(object sender, EventArgs e)
    {
            TreeNode currentNode = TreeFolder.SelectedNode;
                SPFolder oFolder = (SPFolder)currentNode.Tag;
                foreach (SPFile file in oFolder.Files)
                {
                    if (CreateDirectoryStructure(tbDirectory.Text, file.Url))
                    {
                        var filepath = System.IO.Path.Combine(tbDirectory.Text, file.Url);
                        byte[] binFile = file.OpenBinary();
                        System.IO.FileStream fstream = System.IO.File.Create(filepath);
                        fstream.Write(binFile, 0, binFile.Length);
                        fstream.Close();
                    }
                }
    }
//creating directory        
private bool CreateDirectoryStructure(string baseFolder, string filepath)
        {
            if (!Directory.Exists(baseFolder)) return false;
            var paths = filepath.Split('/');
            for (var i = 0; i < paths.Length - 1; i++)
            {
            baseFolder = System.IO.Path.Combine(baseFolder, paths[i]);
            Directory.CreateDirectory(baseFolder);
        }
        return true;
    }

试试这个:

SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
foreach (SPWeb oWebsite in collWebsites)
{

SPFolderCollection collFolders = oWebsite.Folders;
  foreach (SPFolder oFolder in collFolders)
  {
            foreach (SPFile file in oFolder.Files)  
            {
                 // Your code here
            }
  }

}

最新更新