Share some shrepoint code (1)

Source: Internet
Author: User
  1. Traverse all websites and lists

     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. Traverse all objects in a folder
     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. Move files
     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 }

     

     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.