Tuesday, December 28, 2010

SharePoint People Picker Limit Selection

By default, the people picker will let a user select anyone visible to the picker. This is not always an ideal situation. Luckily, there are a couple of ways to easily limit what the user can select from.

First, if you need to limit selection to site collection users, you can use an stsadm command

stsadm -o setproperty –url http://sitecollectionURL
       –pn peoplepicker-onlysearchwithinsitecollection –pv yes


There are a couple of other options to limit selection that involve setup in active directory. They can be found here; Keep it Simple!
Peoplepicker: Stsadm properties


Second, customize the people editor control with the SharePointGroup property. I've found this solution very helpful in customizing input screens as it gives really fine grained control over an individual field. The field below will only allow selection from "SomeGroup".

<SharePoint:PeopleEditor ID="plpEdit" runat="server" SharePointGroup="SomeGroup" />

Sunday, December 26, 2010

SharePoint People Picker Multiple Domains

The people picker is an important part of a SharePoint farm. Making sure that the correct users are available for selection is key. Issues almost always show up in farms where multiple domains need to be available for selection. The fix is a couple of stsadm commands, these commands work in SharePoint 2007 and 2010. 

By default, the application pool identity is used to search active directory. If the account does not have the correct permissions, you will need to encrypt the password for the account that will be used to search that domain. This account needs to be noted for password changes!

Set the encryption key (run on each WFE)
stsadm -o setapppassword -password  *********
Set the domains that should be searched  (run on one WFE per web application)
stsadm -o setproperty -pn peoplepicker-searchadforests 
       -pv domain:domain1;domain:domain2,domain2\account,password 
       -url http://webapp
A more detailed discussion can be found here:
http://blogs.msdn.com/b/joelo/archive/2007/03/08/cross-forest-multi-forest-configuration-additional-info.aspx

Visual Studio 2010 Code Snippets

Code snippets are a great way to speed up development time. In this post I'll go through a simple way to create your own code snippets. I'll be creating a snippet to log to the 14\LOGS files.

Open a Visual Studio project and add a new xml file. Make sure to save it with a .snippet extension.

Right click in the new xml file,  select Insert Snippet and double click on snippet. The xml below will be inserted for you.



Fill in the values you would like for these tag. The most important is the shortcut - its what will start intellisence for you.
    <Title>SharePoint Logging</Title>
    <Author>Me</Author>
    <Shortcut>SPLog</Shortcut>
    <Description></Description>

Choose what type of snippet you want either SurroundsWith or Expansion, I'm using expansion here.
    <SnippetTypes>
      <SnippetType>SurroundsWith</SnippetType>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>

Now enter what you would like to replace in instances of the snippet. Here the component name to be logged changes. If there are more replacements needed, add more Literal tags.
    <Declarations>
      <Literal>
        <ID>Component</ID>
        <Default>CustomComponent</Default>
      </Literal>
    </Declarations>

Change the code language to CSharp.
    <Code Language="CSharp">

Enter the code to be inserted in CDATA[ YOUR CODE GOES HERE  ]
  <![CDATA[
  SPDiagnosticsService.Local.WriteTrace(0,
                    new SPDiagnosticsCategory("$Component$", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
  ]]>


Save the snippet to the default location "C:\Users\Administrator\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets" and your ready to try your new snippet.

Completed snippet file
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>SharePoint Logging</Title>
    <Author>Me</Author>
    <Shortcut>SPLog</Shortcut>
    <Description></Description>
    <SnippetTypes>

      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>Component</ID>
        <Default>CustomComponent</Default>
      </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[
  SPDiagnosticsService.Local.WriteTrace(0,
      new SPDiagnosticsCategory("$Component$", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
  ]]>
    </Code>
  </Snippet>
</CodeSnippet>

Logging in Sharepoint 2010

Logging in SharePoint 2010 is a pretty straight forward affair. The code block below will write to 14\LOGS 

using Microsoft.SharePoint.Administration;

                SPDiagnosticsService.Local.WriteTrace(0,
                    new SPDiagnosticsCategory("CustomComponent", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);

If you want to create your own custom logging component, the following two blogs will assist you.

http://blog.mastykarz.nl/logging-uls-sharepoint-2010/
http://www.sharepointproconnections.com/article/sharepoint-development/SharePoint-Logging-What-s-New-in-SharePoint-2010.aspx