• 分享一些ShrePoint的代码(一)


    1. 遍历所有网站和列表
       1 SPSite oSiteCollection = SPContext.Current.Site;
       2 SPWebCollection collWebsite = oSiteCollection.AllWebs;
       3 
       4 for (int i = 0; i < collWebsite.Count; i++)
       5 {
       6     using (SPWeb oWebsite = collWebsite[i])
       7     {
       8         SPListCollection collList = oWebsite.Lists;
       9 
      10         for (int j = 0; j < collList.Count; j++)
      11         {
      12             Label1.Text += SPEncode.HtmlEncode(collWebsite[i].Title) + "   "
      13                 + SPEncode.HtmlEncode(collList[j].Title) + "<BR>";
      14         }
      15     }
      16 }
    2. 遍历一个文件夹下的所有文件
       1 using (SPWeb oWebsite = new SPSite("http://Server/sites/SiteCollection").OpenWeb())
       2 {
       3     string folderUrl = "/Shared Documents/MySubFolder";
       4     SPFolder oFolder = oWebsite.GetFolder(folderUrl);
       5     SPFileCollection collFile = oFolder.Files;
       6 
       7     foreach (SPFile oFile in collFile)
       8     {
       9         Label1.Text += "<BR>Url: " + oFile.Url.ToString() + " Size: " + oFile.Length.ToString();
      10     } 
      11 }
    3. 移动文件
      
      
       1 SPWeb oWebsite = SPContext.Current.Web;
       2 SPFolder oFolder = oWebsite.GetFolder("Shared Documents");
       3 SPFileCollection collFile = oFolder.Files;
       4 
       5 
       6 List<SPFile> listFiles = new List<SPFile>(collFile.Count);
       7 
       8 foreach (SPFile oFile in collFile)
       9 {
      10     listFiles.Add(oFile);
      11 }
      12 
      13 
      14 foreach (SPFile moveFile in listFiles)
      15 {
      16     moveFile.MoveTo("Shared Documents/StorageFolder/" + moveFile.Name, true);
      17 }
      
      
      
      
      
  • 相关阅读:
    Binary Tree Inorder Traversal
    Populating Next Right Pointers in Each Node
    Minimum Depth of Binary Tree
    Majority Element
    Excel Sheet Column Number
    Reverse Bits
    Happy Number
    House Robber
    Remove Linked List Elements
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/wengnet/p/SP_Code1.html
Copyright © 2020-2023  润新知