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

Sunday, October 3, 2010

ASP.NET Align Labels with Text

The simple task of aligning labels and text can become not so easy when you move away from using tables. In this example I'm wrapping the lables and textboxes in div and using a bit of CSS to produce the result below. The important bits are highlighted.


div{
      clear:left
      margin: 5px 0 0; padding: 1px 3px;
      width: 400px;
}
.input{
      display:block; float: left 
      margin: 0 0 5px; padding: 3px 5px;
      text-align:right;width: 130px;
}




<div>
      <asp:Label AssociatedControlID="txtOne" CssClass="input" ID="label1" runat="server"  
      Text="Text One:"></asp:Label>
      <asp:TextBox ID="txtOne" runat="server"></asp:TextBox>
</div>
<div>
     <asp:Label AssociatedControlID="txtTwo"    CssClass="input" ID="label2" runat="server"
     Text="Text Two:"></asp:Label>
     <asp:TextBox ID="txtTwo" runat="server"></asp:TextBox>
</div>
<div>
     <asp:Label AssociatedControlID="ddlOne" CssClass="input" ID="label3" runat="server" 
      Text="DropDown:"></asp:Label>
     <asp:DropDownList ID="ddlOne" runat="server">
           <asp:ListItem>Choice1</asp:ListItem>
           <asp:ListItem>Choice2</asp:ListItem>
     </asp:DropDownList>
</div>
<div>
    <asp:Label AssociatedControlID="txtThree" CssClass="input" ID="label4" runat="server"  
    Text="Text Three:"></asp:Label>
    <asp:TextBox ID="txtThree" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox>
</div>
<div>
    <asp:Label AssociatedControlID="txtFour" CssClass="input" ID="label5" runat="server"
    Text="Text Four:"></asp:Label>
    <asp:TextBox ID="txtFour" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox>
</div>

Saturday, July 31, 2010

Enable IntelliSense for SharePoint Client Object Model in Visual Studio 2010

Microsoft released some guidance on enabling intellisense for the SharePoint client object model and was disappointed, it only gave partial intellisense. After a bit of investigating, I found that there are a number of debug.js files in the layouts folder. Adding the SP.Core.debug.js file gave me the result I was looking for. 

<script type="text/javascript" src="/_layouts/MicrosoftAjax.js" ></script>
<script type="text/javascript" src="/_layouts/SP.debug.js" />
<script type="text/javascript" src="/_layouts/SP.Core.debug.js" />


Sunday, July 25, 2010

Table of Contents Web Part

The table of contents web part isn't showing all the sites. Go to site settings, navigation and increase the number of sites to display.