Mock 70-541 — MSTS: Microsoft Windows SharePoint Services 3.0 - Application Development (CS)

Here are some mock exam questions for the 70-541, created by some random guy. You can click an alternative to see if it's correct () or incorrect ().

When the questions talk about /A/B/C in the context of XML, it means <A><B><C>This element</C></B></A> (like in XPath)

If you refresh the page, all your answers will be lost and the alternatives reshuffled

You want to run some custom code when a feature is activated. What do you do?

Modify the Feature tag in the feature.xml to include the ReceiverAssembly and ReceiverClass attributes
Add a /Elements/Receivers/Receiver tag in elements.xml with the type FeatureActivated
Add a /Feature/Receivers/Receiver tag in feature.xml with the type FeatureActivated
Override the OnActivated method in the feature class
You have written a web part with a setting "MaxRows". How do you make this setting configurable from the web part designer?

Annotate the member like this:
[WebDisplayName("Max rows")]
[WebDescription("The maximum number of rows to show")]
public int MaxRows { get; set; }
Annotate the member like this:
[WebConfigurable("Max rows", "The maximum number of rows to show")]
public int MaxRows { get; set; }
Annotate the member like this:
public int MaxRows { get; set; }
and then set the Name and Description for guid in the .webpart file
Annotate the member like this:
public int MaxRows { get; set; }
and then set the Name and Description for "MaxRows" in the .webpart file.
A coworker wants to know what a "Ghosted" page is. What do you tell him? (choose two)

A ghosted page has not been modifed by the user
Ghosted pages are read from the front-end web server
A ghosted page has been modified by the user
Ghosted pages are read from the content database
You want a web part to run some code that requires administrator privileges on the site. How do you run this code?

Use SPSecurity.RunWithElevatedPrivileges(...)
Use SPSecurity.RunAsSiteAdministrator(...)
Web parts are run on the server side, so they always run with site administrator privileges
Create a method in the web part and annotate it with [SharePointPermission(SecurityAction.Demand)], and put the code in there
You have created a feature that lets users tweak the look of a site. You want to add a link for this to the site's Site Settings page. What do you do?

Add a <customAction Location="Microsoft.Sharepoint.SiteSettings" GroupId="Customization" Title="Tweak look"><UrlAction Url="_layouts/yourFeature.aspx" /><customAction> element to the feature's element manifest.
Copy settings.aspx from the sharepoint site, add the link to _layouts/yourFeature.aspx, and put it in TEMPLATE\LAYOUTS in your feature solution together with yourFeature.aspx.
Create a feature event receiver with the following code:
var settings = mySpSite.SiteSettings;
settings.Add(new SPSiteSetting("Tweak look", "Customization", "_layouts/yourFeature.aspx"));
Modify the site template, add a <NavBar Name="SharePoint Site Settings" ID="1002"> <NavBarLink Name="Tweak settings" Url="_layouts/yourFeature.aspx" /> <NavBar>
You have created a set of features for the SharePoint Central Administration. You want to create a page similar to the Operations and Application Management pages, where links to all your features' pages can be organized. How do you create such a page?

Create an aspx page with a FeatureLinkSection, and add links through customActions in each feature
Use Microsoft Frontpage (or DreamWeaver or similar tool), and either publish the page directly to the site or add it to the main feature's TEMPLATE\LAYOUTS directory
Browse to the Operations page, save the html and use it as a template for your custom page, modifying texts and links as needed
Register a new SPSiteSettings object in the main feature, and add links by adding SPSiteSetting objects in each feature
You have created a new list template where users can register their personal goals for a project. Users should be able to read all items, but should only be able to modify their own. How do you specify this in the template?

Add the attribute SecurityBits="12"
Add the attributes ReadPermissions="All" WritePermissions="User"
Add the attributes OwnerPermissions="Read,Edit" DefaultPermissions="Read"
Add the attribute SecurityMode="EditUserOnly"
Which statement best describes a content type?

A content type is a set of fields that items of that type can specify
A content type is a logical grouping of file types, like Excel Spreadsheet (.xls, .xlsx, .csv) or Word Document (.doc, .docx)
A content type is a class that inherits SPItem (like SPListItem and SPSimpleItem) to add additional fields
A content type is a SharePoint type whose dependencies are all satisfied
You want to create a list that can support multiple content types. How can you do this? (choose two)

Add the attribute DisallowContentTypes="false" to the ListTemplate element
Get a reference to the list and set spList.ContentTypesEnabled = true;
Get a reference to the list and run spList.ContentTypes.Add(...); for all the required content types
Add all the required content types to the list schema in /List/MetaData/ContentTypes/ContentType nodes
You have developed a set of features for a customer, and now it's time to hand over the result. How should you package your product?

Create SharePoint solution package that the administrator can install
Create a .msi Windows Installer package that the administrator can install
Add deployment build events to the Relase configuration of all the projects. Create a .zip file that the administrator can unpack and build.
Create a clean SharePoint site, deploy your solution to it, and copy the files from the sharepoint root so that the administrator can merge them with their site
You have written a feature that requires an entry in web.config to work. What is the best way to add this modification?

Create a SPWebConfigModification object with the changes, and call spWebService.WebConfigModifications.Add(modification) , update and apply.
Call File.OpenText(spSite.WebApplication.BaseDirectory+"\\web.config"); to open the web .config, and write the contents to the appropriate place. Run iisreset, and iisadm -deployconfig if you are in a farm.
Manually edit the web.config and add it to feature directory. Add <ElementFile Location="web.config" /> to feature.xml.
Document the changes required and give a useful error message if the administrator neglects to do them.
A coworker has created a number of quick and ugly but useful debugging features, but finds it time consuming to activate and deactivate them all every time the manager or the customer wants a demo of something. How will you suggest that he automates it?

Create a batch file that runs stsadm -activatefeature -name FeatureName -site http://localhost/sites/demo for each feature, and likewise with -deactivatefeature afterwards.
Create a feature called MainDebugger, and add an ActivationDependency in each of the debugging features to let them all be turned on and off together with MainDebugger.
Declare the features' scope as Transient, and run iisreset to cause them all to be deactivated
Use a tool like Visual Studio Web Test to record the actions needed to activate and deactivate the features.
You have created a custom list type for internal use. You do not want users to be able to create instances of the list from the Create page. How can you disable this?

Set Hidden="TRUE" in the ListTemplate tag in the element manifest.
Set Hidden="TRUE" in the List tag in the list schema (ONET.xml)
Set Hidden="TRUE" in the ListInstance tag in the element manifest
Set spList.Hidden = true; in the feature receiver
A customer is worried about CSRF attacks, where a <img src="http://somehost/sites/foo/_layout/deleteItem.aspx?id=42" /> placed on a third party will cause a request to your site that deletes an item. What do you tell them?

SharePoint does not allow database updates on GET requests, unless SPWeb.AllowUnsafeUpdates is set to true
SharePoint does not support automatic image generation, so the image will just show a "broken" image icon
SharePoint only allows requests from other servers in the farm, so this type of exploit doesn't apply
SharePoint supports CSS 2, and CSRF is disabled under system.web in web.config by default.
You have created two web parts, one that shows the most recent entries in each Event Log (the selector), and another that displays more information from a single Event Log (the viewer). You want to let users connect the selector to the viewer from the web part editor. What do you do?

Create an interface for getting the event log to show, add a method [ConnectionProvider("Event log provider")] public IEventLogSelection GetEventLog(); in the selector, and [ConnectionConsumer("Event log consumer")] public void SetEventLog(IEventLogSelection e); in the viewer.
Create an interface for getting the event log to show, add a property [WebProperty] public IEventLogSelection EventLog { get { ... } } in the selector and a [WebProperty] public IEventLogSelection EventLog { set { ... } }; to the viewer.
Create an interface for getting the event log to show, add a property [WebProperty(typeof(IEventLogSelection))] public object EventLog { get { ... } } in the selector and a [WebProperty(typeof(IEventLogSelection)] public object EventLog { set { ... } }; to the viewer.
Make the selector set a field in the session data to the event log to view, and let the event log viewer show it.
You want to download an RSS feed from a server every 15 minutes, and create items and alerts based on it. How do you run a task every 15 minutes?

Create a class extending SPJobDefinition, override the Execute method. Schedule it with an SPMinuteSchedule with the interval set to 15.
Create an Execute method and start it in a Thread. Let the thread run in a loop, sleeping for 15 minutes after each download, until the feature is deactivated.
Create a SPTimerJob, set the Interval property and override the Execute method. Package it as a .wsp solution file, and run stsadm -o createtimerjob -filename YourJob.wsp -url http://somehost/sites/foo
Create an application page that does the job when requested. Provision it in the feature, but don't show links. Create a Windows Scheduling job that runs every 15 minutes, and downloads the page.
You want to create a feature that lets an administrator add items to a list, posing as a user. How can you impersonate the user account?

Get the desired SPUser from SPWeb.AllUsers, then create a new SPSite object with the spUser.UserToken
Create an SPUser with the user's username and password, and run spSite.Impersonate(user);
Get the desired SPUser from SPWeb.AllUsers, then run spSite.Impersonate(user);
Create an SPUser with the user's username and password, and create a new SPSite object with the spUser.UserToken
You want to show a list of all the hosts participating in the current farm, given your SPWeb object. How can you obtain such a list?

(SPServerCollection) spWeb.Site.ExtendedProperties["Servers"]
You want to register an ItemAdding event listener on a list through the object model. How can you achieve this?

spList.Events.Add(SPEventReceiverType.ItemAdding, "(full assembly name)", "classname");
spList.RegisterEvent(SPEventReceiverType.ItemAdding, typeof(MyHandler));
var foo = spList.Events.Add(); foo.Type = SPEventReceiverType.ItemAdding; foo.Handler = new MyHandler(); foo.Update();
spList.Events.Add(new SPListEventReceiver(typeof(MyHandler)));
You have an SPList that you wish to add the the quick launch menu. How can you do this programmatically?

spList.OnQuickLaunch = true; spList.Update();
var navBar = spList.ParentWeb.NavBars["QuickLaunch"]; var link = navBar.Add(); link.Title = spList.Title; link.Url = spList.Url; link.Update();
spList.ParentWeb.NavBars["QuickLaunch"].Add(spList.Title, spList.Url)

Good luck on your real exam!