簡體   English   中英

我可以將整個SPSite或SPWeb下載到硬盤嗎(ATM我只能下載1個文件夾)

[英]can I download entire SPSite or SPWeb to harddisk (ATM i can only download 1 folder)

我做了一個Windows窗體應用程序,它以樹狀視圖的形式映射整個spsite(在文本框中給出),但是我想知道用戶是否選擇下載整個Site,我需要什么代碼,我調查了google,但找到了代碼下載下面給出的一個文件或文件夾,

下載資料夾

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
            }

  }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM