Professional Documents
Culture Documents
Development Platform Stack: Friday, May 11, 2012 5:07 PM
Development Platform Stack: Friday, May 11, 2012 5:07 PM
Session 2 Page 1
Session 2 Page 2
Object Model
Saturday, May 12, 2012 4:05 PM
SPContentDatabase has a Sites property that holds all its child SPSite objects. SPContentDatabase has many members that can be used for developing administration functionality. Some of the more important members can help in the administration of the following: * Backup and restoration of the database * Upgrades of the database * Migration of (moving) the database * Repairs of the database * The database connection string and logon username and password * Limiting the number of site collections Most of the properties of SPContentDatabase are read-only. SPSite many members that you can use to develop administration functionality. Some of the more important members can help in the administration of the following: * The maximum length of Web site URLs * RSS feeds * Auditing * Dead Web sites * Features * Ownership of the site collection * Size quotas for the site collection * Site usage data * Workflows in the site collection * Templates and Web part galleries * Self-service site creation
Session 2 Page 3
Session 2 Page 4
Session 2 Page 5
Session 2 Page 6
Session 2 Page 7
Session 2 Page 8
Session 2 Page 9
Customization
Changes that are made to a SharePoint environment using the browser interface or a tool like SharePoint Designer. Customizations are changes that get stored in a SharePoint content database and have no relationship to a file on the filesystem.
Development
Usually refers to the creation of solution packages and features that deploy assemblies and/ or other files to the SharePoint server(s) in your farm. These files might add content to a content database, but they originate as fi les on the file system. Development is often done using a tool like Visual Studio.
Session 2 Page 10
Class Name SPFarm SPWebApplication SPSite SPWeb SPList SPListItem SPFolder SPFile SPGroup SPUser SPContentType SPField SPView
Description The very top - level object, providing access to configuration information for the entire SharePoint farm A load - balanced IIS web application that is part of the SharePoint farm A site collection inside a web application An individual site within a site collection A list within a particular site An item in a SharePoint list A folder within a SharePoint site A document stored in a SharePoint list A SharePoint group A SharePoint user A content type A column (either a site column or a list column, depending on its location) The view on a particular list
Session 2 Page 11
using (SPSite hrSite = new SPSite("http://intranet/sites/hr")) { SPWeb healthWeb = hrSite.OpenWeb("health"); string title = healthWeb.Title; }
Session 2 Page 12
Console Application
Friday, May 18, 2012 10:03 PM
Session 2 Page 13
Object Disposal
Friday, May 18, 2012 9:42 PM
Its often necessary to explicitly dispose of SharePoint objects like SPSite and SPWeb to prevent them from remaining active and taking up an increasing amount of server memory. Using Block Explicitly in Try/catch and Finally
using (SPSite intranetSiteCollection = new SPSite("http://intranet/")) { SPWebCollection websCollection = siteCollection.AllWebs; foreach (SPWeb web in websCollection) { Console.WriteLine(web.Title); web.Dispose(); } Console.Read(); }
When retrieving SPSite or SPWeb objects directly from the SPContext.Current object, you should not explicitly dispose of the objects SPSite siteCollection = SPContext.Current.Site; SPWeb topLevelSite = siteCollection.RootWeb; SPWebCollection webs = topLevelSite.Webs; SPWeb subsiteA = webs["Subsite A"];
Session 2 Page 14
Examples
Friday, May 18, 2012 9:55 PM
Open Grand child web using (SPSite sc = new SPSite("http://intranet/"); { SPWeb rootWeb = sc.OpenWeb(); rootWeb.Dispose(); SPWeb web = sc.OpenWeb("subsite1/subsite2"); web.Dispose(); } List
ListItem SPListItem myListItem = myList["My List Item"]; Update MasterPage SPWeb currentWeb = SPContext.Current.Web; currentWeb.MasterUrl = "/_catalogs/masterpage/Custom.master"; currentWeb.Update(); Create New Web, List , ListItem
SPWeb newWeb = SPContext.Current.Web.Webs.Add("MyNewSubsite"); SPList newList = newWeb.Lists.Add("New List", "Another list", SPListTemplateType.GenericList); SPListItem newListItem = newList.Items.Add(); newListItem["Title"] = "New List Item"; newListItem.Update();
SPContext.Current.Web.Lists["Invoices"].Delete();
Session 2 Page 15
List Folders StringBuilder folderName = new StringBuilder(); using (SPSite site = new SPSite("http://intranet/")) { using (SPWeb web = site.RootWeb) { foreach (SPFolder folder in web.Folders) { folderName.Append(folder.Name); folderName.Append(" "); folderName.Append(folder.SubFolders.Count); folderName.Append("<br>"); } } } Add Folder SPContext.Current.Web.Folders.Add("NewFolder");
Upload File
//Instantiate a new site collection object using (SPSite site = new SPSite("http://intranet/")) { //Get the list object inside the subsite SPWeb web = site.OpenWeb("sites/HR"); SPFolder listFolder = web.Lists["Documents"].RootFolder; string folderUrl = web.ServerRelativeUrl + listFolder.Url; string fileUrl = folderUrl + "/Application.docx"; FileStream stream = System.IO.File.Open(@"C:\Application.docx", FileMode.Open); byte[] contents = new byte[stream.Length]; stream.Read(contents, 0, (int)stream.Length); stream.Close(); SPFile file = web.Files.Add(fileUrl, contents); SPListItem listItem = file.Item; listItem["Title"] = "Job Application"; listItem.Update(); web.Dispose(); }
Session 2 Page 16