MCTS - Microsoft Certified Technology Specialist SharePoint 2010 Application Development Questions and Answers 1 — Questions and Answers
Question 1: A developer needs to implement a business rule that prevents users from deleting a document in a specific library if its 'Approval Status' is 'Approved'. The operation must be cancelled before the item is moved to the recycle bin, and a custom error message must be shown. Which type of event receiver is required to accomplish this?
- An asynchronous ItemDeleted event receiver
- A synchronous ItemAdded event receiver
- An asynchronous ItemDeleting event receiver
- A synchronous ItemDeleting event receiver (Correct answer)
Correct answer: A synchronous ItemDeleting event receiver
To cancel an action before it is committed to the database, a synchronous 'before' event must be used. These events are named with an '-ing' suffix, such as 'ItemDeleting'. Synchronous events execute in the same thread as the user action and allow the operation to be cancelled by setting the 'Cancel' property of the event properties object to true. Asynchronous '-ed' events fire after the action is complete and cannot be used for cancellation.
Question 2: When constructing a Collaborative Application Markup Language (CAML) query in SharePoint 2010 to filter list items, which element must be used to combine two separate conditions with a logical AND?
- <And> (Correct answer)
- <Combine>
- <Where>
- <Both>
Correct answer: <And>
In CAML, the `<And>` element is used to perform a logical AND operation between two conditions. Both conditions must be nested inside the `<And>` tags. The `<Where>` element is the main container for the entire query filter, but it does not perform the logical combination itself. `<Combine>` and `<Both>` are not valid CAML elements for this purpose.
Question 3: A developer creates a SharePoint Feature containing a custom list definition and several associated site columns. The requirement is that this list template must be available for use on any site within a specific site collection, but should not be available in other site collections. What is the most appropriate scope for this Feature?
- Web
- Site (Correct answer)
- Farm
- WebApplication
Correct answer: Site
The 'Site' scope corresponds to the site collection level. Activating a Feature at this scope makes its elements, like list definitions and site columns, available throughout that entire site collection and any subsites within it. The 'Web' scope is too narrow (a single site), while 'WebApplication' and 'Farm' scopes are too broad for this requirement.
Question 4: A developer is building a WPF desktop application that will run on client machines outside of the SharePoint farm. The application needs to retrieve and update list items from a SharePoint 2010 site without using legacy ASMX web services. Which API is specifically designed for this remote, managed code scenario?
- Server-Side Object Model
- Business Connectivity Services (BCS)
- .NET Client-Side Object Model (CSOM) (Correct answer)
- RESTful (ListData.svc) API
Correct answer: .NET Client-Side Object Model (CSOM)
The .NET Client-Side Object Model (CSOM) was introduced in SharePoint 2010 to allow remote .NET managed applications (like WPF, Console, or WinForms apps) to interact with SharePoint data. It provides a familiar, object-oriented programming model that is a subset of the server-side API. The Server-Side Object Model can only run on SharePoint servers. BCS is for connecting to external data, and while SharePoint 2010 had a limited REST API, the CSOM was the primary and more robust choice for full-featured client applications.
Question 5: You are creating a custom Web Part for a collaborative dashboard. The Web Part has a property that allows each user to specify their favorite report from a list. You need to ensure that when one user sets this property, it does not affect the view for other users. Which attribute must be applied to the property in the Web Part's code-behind?
- [WebBrowsable(true)]
- [Category("Settings")]
- [ExportMode(ExportMode.All)]
- [Personalizable(PersonalizationScope.User)] (Correct answer)
Correct answer: [Personalizable(PersonalizationScope.User)]
The `[Personalizable]` attribute is used to make a Web Part property configurable by users. By setting the scope to `PersonalizationScope.User`, the property's value is stored on a per-user basis. `PersonalizationScope.Shared` would store one value for all users. `[WebBrowsable(true)]` makes the property visible in the editor tool pane, and `[Category(...)]` organizes it, but neither controls the storage scope.
Question 6: You are developing a custom SharePoint 2010 timer job that needs to run in the background to perform maintenance tasks across multiple site collections in a web application. Which object from the server-side object model is the most appropriate starting point for your code, given that there is no HTTP context available?
- SPFarm.Local (Correct answer)
- SPContext.Current
- new SPSite(url)
- SPList
Correct answer: SPFarm.Local
In a non-HTTP context like a timer job or console application, `SPContext.Current` is not available. The correct approach is to start from the top of the farm hierarchy with `SPFarm.Local`. From the farm object, you can navigate down to web services, then to a specific `SPWebApplication`, and then iterate through its `Sites` (site collections) collection to perform your tasks.
A developer needs to implement a business rule that prevents users from deleting a document in a specific library if its 'Approval Status' is 'Approved'.
The operation must be cancelled before the item is moved to the recycle bin, and a custom error message must be shown.
Which type of event receiver is required to accomplish this?