Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Save C# Time with .OpenWeb()

One of my most common coding task is a simple command line EXE that takes a few parameters in, opens the object model, and applies some sort of changes.   Yes, I know about PowerShell, but am very comfortable with Visual Studio and Intellisense today.

Action Steps

  1. Start a new “Console Application” project type
  2. Add an assembly reference for “Microsoft.SharePoint.dll”   (12.0.4518.1016)
  3. Type “SPSite s” and right click to add the “using” statement.   Very nice shortcut, thank you Joel G!
  4. Create a new SPSite object and use the full URL to the web for the constructor
  5. Use the SPSite.OpenWeb()  method to grab that one web object without the hassle of looping through children
  6. This trick works no matter how far the SPWeb is nested down in the site collection

 

image
image

 

image

 

image

 

image

 

image

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲