My SharePoint Blog

Blogs On SharePoint Technologies


Search Site


My SharePoint Blog recommends any of the following books...


Recent comments

Tags

None

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    How to use the PeoplePicker in SharePoint

    I found this blog on how to do it.

    Here is the basic idea..

     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.Drawing;
    public partial class _Default : System.Web.UI.Page
    {
        private PeopleEditor objEditor;
        protected void Page_Load(object sender, EventArgs e)
        {
            objEditor = new PeopleEditor();
            objEditor.AutoPostBack = true;
            objEditor.PlaceButtonsUnderEntityEditor = true;
            objEditor.ID = "pplEditor";
            objEditor.AllowEmpty = false;
            objEditor.SelectionSet = "User,SecGroup,SPGroup";
            objEditor.MultiSelect = false;
            Panel1.Controls.Add(objEditor);
        }
        private string GetAccountName()
        {
            string strAccountName = String.Empty;
            for (int i = 0; i < objEditor.ResolvedEntities.Count; i++)
            {
                PickerEntity objEntity = (PickerEntity)objEditor.ResolvedEntities[i];
                SPUserInfo objInfo = new SPUserInfo();
                objInfo.LoginName = objEntity.Key;
                strAccountName = objInfo.LoginName;
                // to return a sharepoint people group formatted string use...
                // strAccountName = objEntity.EntityData["SPUserID"].ToString() + ";#" + objEntity.DisplayText.ToString();
            }
            return strAccountName;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string strAccountName = GetAccountName();
            Label1.Text = "account name: " + strAccountName;
        }
    }


    Or via HTML:

    <SharePoint:PeopleEditor runat="server" ID="pplEditor"
            AutoPostBack="true" AllowEmpty="false" SelectionSet="User,SecGroup,SPGroup"
            BorderWidth="1" Width="200px" PlaceButtonsUnderEntityEditor="false" Rows="1" />

     

    For this code to work you must publish it to a SharePoint website. You cannot run it from the Visual Studio debugger. 

    Here is the MSDN class reference.


    Categories: SharePoint
    Posted by Kevin on Friday, July 20, 2007 3:07 PM
    Permalink | Comments (11) | Post RSSRSS comment feed

    Using ASP.Net user controls in your WSSV3/MOSS ASPX pages.

     

    See this blog.


    Categories: SharePoint
    Posted by Kevin on Friday, July 20, 2007 9:07 AM
    Permalink | Comments (0) | Post RSSRSS comment feed

    How to enable debugging in WSS 3.0

    How to enable debugging in WSS 3.0 Renaud Comte has a great tip on how to get the full ASP.NET errors appearing in WSS 3.0. The detail is to add the following item to your Web.Config (C:\Inetpub\wwwroot\wss\VirtualDirectories\80):

     

    <SafeMode MaxControls="200" CallStack="false" ...>
    <!-- Becomes -->
    <SafeMode MaxControls="200" CallStack="true" ...>
     
    <customErrors mode="On" />
    <!-- Becomes -->
    <customErrors mode="Off" />
     
    <compilation batch="false" debug="false">
    <!-- Becomes -->
    <compilation batch="true" debug="true">

    Categories: SharePoint
    Posted by Kevin on Thursday, July 12, 2007 2:07 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    SharePoint - Establishing Site Context

    Using SPContext and making a application globally availible

    Categories: SharePoint
    Posted by kevin on Thursday, July 12, 2007 1:07 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    Update a Person or Group field in SharePoint with C#

    Make sure to add your .NET reference to Windows SharePoint Services dll. This is a simple console app...

     

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    namespace UserNameListTester
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    SPSite siteCollection = new SPSite("http://localhost");
                    SPWeb mySite = siteCollection.OpenWeb("/");
                    SPListItemCollection listItems = mySite.Lists["UserNameListTester"].Items;
                    Console.WriteLine("Read in the existing values****************************");
                    for (int i = 0; i < listItems.Count; i++)
                    {
                        SPListItem item = listItems[i];
                        Console.WriteLine(item["PersonOrGroupColumn"].ToString());
                    }
                    Console.WriteLine("Writing new values**************************************");
                    for (int i = 0; i < listItems.Count; i++)
                    {
                        SPListItem listItem = listItems[i];
                        //listItem["Created By"] = mySite.Users["domain\\cornwell"];
                        // get the current logged on user
                        string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
                        listItem["Created By"] = mySite.Users[currentUser];
                        listItem.Update();
                    }
                    Console.WriteLine("Read out changed values*******************************");
                    for (int i = 0; i < listItems.Count; i++)
                    {
                        SPListItem item = listItems[i];
                        Console.WriteLine(item["PersonOrGroupColumn"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Shit: " + ex.Message.ToString() + ex.Source.ToString() + ex.ToString());
                }
                finally
                {
                    string foo = Console.ReadLine();
                }
            }
        }
    }

      


    Categories: SharePoint
    Posted by Kevin on Monday, July 09, 2007 2:07 PM
    Permalink | Comments (5) | Post RSSRSS comment feed