I’ve been meaning to post my thoughts about my recent foray into Sharepoint for awhile now and since I finally have some time, here goes.

Development on Sharepoint sucks if you’re not doing it directly on the server.

-I can’t even count the number of hours I’ve spent copying a .cab file to the server, running stsadm.exe -o addwppack and restarting IIS.

Documentation for development on Sharepoint sucks.

-This was the first time I’ve ever developed against a platform with such limited documentation/examples. While it was pretty interesting, I would prefer to not do something like this again.

That being said, I thought I would post some of the code that I’ve written that may be useful. This first webpart allows you to search for users in the AD tree associated with your site:

private DataTable Search() { SPSite siteCollRoot = new SPSite(SPContext.Current.Site.Url); DataTable dt = new DataTable(); //must log in to the SSP and give the NT_AuthorityAuthenticated //users the Manage User Profiles and Personal site permissions //here (http://localhostssp/admin/_layouts/ManageServicePermissions.aspx) //in order for the code below to work //for all users SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite siteColl = new SPSite(siteCollRoot.ID)) { ServerContext context = ServerContext.GetContext(siteColl); UserProfileManager upm = new UserProfileManager(context); UserProfile currentProfile; IEnumerator enumProfs = upm.GetEnumerator(); bool continueEnum = true; DataColumn dc = new DataColumn("Title"); dt.Columns.Add(dc); dc = new DataColumn("EMail"); dt.Columns.Add(dc); dc = new DataColumn("JobTitle"); dt.Columns.Add(dc); dc = new DataColumn("Department"); dt.Columns.Add(dc); dc = new DataColumn("WorkPhone"); dt.Columns.Add(dc); dc = new DataColumn("ID"); dt.Columns.Add(dc); dc = new DataColumn("LastName"); dt.Columns.Add(dc); dc = new DataColumn("FirstName"); dt.Columns.Add(dc); while (continueEnum) { try { continueEnum = enumProfs.MoveNext(); } catch (Exception e) { Console.WriteLine("EXCEPTION in enum: " + e.ToString()); continueEnum = enumProfs.MoveNext(); } currentProfile = (UserProfile)enumProfs.Current; try { DataRow dr = dt.NewRow(); dr["ID"] = currentProfile.ID.ToString(); dr["Title"] = currentProfile["PreferredName"].ToString(); dr["EMail"] = currentProfile["WorkEmail"].ToString(); dr["JobTitle"] = currentProfile["Title"].ToString(); dr["Department"] = currentProfile["Department"].ToString(); dr["WorkPhone"] = currentProfile["WorkPhone"].ToString(); dr["LastName"] = currentProfile["LastName"].ToString(); dr["FirstName"] = currentProfile["FirstName"].ToString(); dt.Rows.Add(dr); } catch (Exception ex) { } } } }); return dt; }