Which code segment should you use?

You are creating a site on a SharePoint 2007 server. You write the following code segment:

01: Public Function GetUserProperties() As String
02: Dim usersWithNoTitles as String = New String(“”)
03: Dim site as SPSite = new SPSite(“http://sitename”)
04: Try
05: Dim web as SPWeb = site.OpenWeb
06: Try
07: Dim profMan as UserProfileManager = New UserProfileManager
08: …
09: Finally
10: CType(web.iDisposable).Disposable()
11: End Try
12: Finally
13: CType(site.iDisposable).Disposable()
14: End Try
15: Return usersWithNoTitles
16: End Function

You need to display a list of users in the site who have blank titles.

Which code segment should you use?

You are creating a site on a SharePoint 2007 server. You write the following code segment:

01: Public Function GetUserProperties() As String
02: Dim usersWithNoTitles as String = New String(“”)
03: Dim site as SPSite = new SPSite(“http://sitename”)
04: Try
05: Dim web as SPWeb = site.OpenWeb
06: Try
07: Dim profMan as UserProfileManager = New UserProfileManager
08: …
09: Finally
10: CType(web.iDisposable).Disposable()
11: End Try
12: Finally
13: CType(site.iDisposable).Disposable()
14: End Try
15: Return usersWithNoTitles
16: End Function

You need to display a list of users in the site who have blank titles.

Which code segment should you use?

A.
For each user as SPUser in web.AllUsers
Dim p as UserProfile = profMan.GetUserProfile(User.ID)
If PropertyOf(PropertyConstants.Title).ToString.Length = 0 Then usersWithNotitles.Add User.Name
End If
Next

B.
For each user as SPUser in web.AllUsers
Dim p as UserProfile = profMan.GetUserProfile(null)
If p(PropertyConstants.Title).ToString.Length = 0 Then
usersWithNoTitles.Add(p.ID.ToString())
End If
Next

C.
For each user as SPListItems in web.Lists(“All Users”).item
Dim p as UserProfile = profMan.GetUserProfile(User.ID)
If p(PropertyConstants.Title).ToString.Length = 0 Then
usersWithNoTitles.Add(User.Name)
End If
Next

D.
For each p as Property in profMan.Properties
If p.Name = “Title” and also Not p.IsVisibleOnViewer Then
For each user as SPUser in web.AllUsers
usersWithNoTitles.Add(User.Name)
Next
End If
Next



Leave a Reply 0

Your email address will not be published. Required fields are marked *