Bandar Aljahani

Hi,

Is there a way to get other information from "Created By" field on sharepoint list like email, tel and other user profile I would like to view it beside the created by field on a list.

Thanks a lot...



Re: SharePoint - Development and Programming Showing users' profile data on sharepoint list

Peter ebSms

SPListItem spListItem = spList.GetItemById([the int ID of the list entry]);

SPField spField = spListItem.Fields.GetFieldByInternalName("Author");

string displayName = spField.Title;

string author = spListItem[displayName].ToString();

int userId = Convert.ToInt32(author.Substring(0, author.IndexOf(";#")));

SPUser spUser = spWeb.AllUsers.GetByID(userId);

string email = spUser.Email;

Greetings, Peter





Re: SharePoint - Development and Programming Showing users' profile data on sharepoint list

Bandar Aljahani

Thanks for your reply,

After this code how I can put th field on the list I'm afraid I'm not much expert on sharepoint development.

Thanks a lot..





Re: SharePoint - Development and Programming Showing users' profile data on sharepoint list

Peter ebSms

Hi Bandar,

i can think of a few possibilities, but they all need some coding. Perhaps someone has a simpler solution but i would do it with an Event Receiver. With an Event Receiver you can plug self written code to an event of a list item e.g. when the item is updating or already updated, a new item will be made or is already made.

1. add a few fields to your list like Email, Name and all the fields you would like to show from the users profile

2. in Visual Studio 2005 code an Event Receiver and sign the assembly (Menu Project -> [Projectname] Properties... -> Signing -> Check sign the assembly and generate a new string name key file

Code Block

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.SharePoint;

namespace MyNamespace.EventHandlers
{
public class MyItemHandler : SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
; // update your list fields with the users profile values

}

public override void ItemUpdating(SPItemEventProperties properties)
{
; // update your list fields with the users profile values
}

}
}

3. in the events fill the fields of your newly added fields with values from the users profile

4. to make it more simple for you during development, run your event receiver assembly with full trust by installing it to the global assembly cache

5. stick your event receiver once to the list e.g. by just two lines of code. You will find also some tools for that on the internet.

myList.EventReceivers.Add(SPEventReceiverType.ItemAdding, AssemblyName, ClassName);
myList.EventReceivers.Add(SPEventReceiverType.ItemUpdating, AssemblyName, ClassName);

Have a look to the SDK.

What helped me alot was "Inside Microsoft Windows SharePoint Services 3.0" from Ted Pattison and Daniel Larson (Microsoft Press). Great book which will bring you fast on more speed with SharePoint development.

Greetings, Peter





Re: SharePoint - Development and Programming Showing users' profile data on sharepoint list

Bandar Aljahani

Thanks peter..

I guess I'll give it a try.

Regards