Here are a few more points about SSOM in SharePoint:
SSOM is typically used when you need to perform tasks that are too complex or resource-intensive to be done using client-side technologies such as JavaScript or the REST API. For example, if you need to perform a large number of data operations or perform operations that require elevated permissions, SSOM may be a good choice.
One of the advantages of using SSOM is that it provides a rich set of objects and methods that are specific to SharePoint. This can make it easier to work with SharePoint data and functionality compared to using more generic technologies such as the REST API.
SSOM code is executed on the server, which means that it can be more efficient than client-side technologies that require data to be transferred back and forth between the client and server. However, this also means that SSOM code can be more difficult to debug, since it is not running in the context of a web browser.
SSOM code is compiled and runs in a trusted environment, which means that it has access to all of the resources and functionality of the server. This can be both an advantage and a disadvantage, as it means that SSOM code has the potential to be more powerful and flexible, but it also means that it has the potential to cause more problems if it is not well-written or used correctly.
Here is a simple example of how you might use SSOM to create a new list in a SharePoint site:
This code creates a new instance of the "SPSite" class, which represents a top-level site in a SharePoint site collection. It then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. Finally, it creates a new list using the "Add" method of the "Lists" collection, and sets the "OnQuickLaunch" property to "true" to add the list to the quick launch navigation of the site.
Here is another example of how you might use SSOM to retrieve and display a list of all the lists in a SharePoint site:
This code creates a new instance of the "SPSite" class, and then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. It then uses a "foreach" loop to iterate through the "Lists" collection of the "SPWeb" object, and prints the title of each list to the console.
Here is another example of how you might use SSOM to retrieve and display the names of all the users in a SharePoint site:
This code creates a new instance of the "SPSite" class, and then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. It then uses a "foreach" loop to iterate through the "SiteUsers" collection of the "SPWeb" object, and prints the name of each user to the console.
Another example of how you might use SSOM to create a new document library in a SharePoint site:
This code creates a new instance of the "SPSite" class, and then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. It then retrieves the "ListTemplate" object for a document library, and uses the "Add" method of the "Lists" collection to create a new document library based on this template. It then sets the "OnQuickLaunch" property to "true" to add the library to the quick launch navigation of the site.
Example of how you might use SSOM to retrieve and display the properties of a list item in a SharePoint list:
This code creates a new instance of the "SPSite" class, and then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. It then retrieves a reference to the "SPList" object for a list with the title "My List", and gets the first item in the list using the "Items" collection. It then iterates through the fields of the item, and prints the internal name and value of each field to the console.
Example of how you might use SSOM to retrieve and display the permissions of a list in a SharePoint site:
This code creates a new instance of the "SPSite" class, and then uses the "OpenWeb" method to get a reference to the root "SPWeb" object of the site. It then retrieves a reference to the "SPList" object for a list with the title "My List", and iterates through the "RoleAssignments" collection of the list. For each role assignment, it prints the name of the member (i.e., the user or group) and the roles that have been assigned to them.
0 Comments