SharePoint List Management

Working with MOSS 2007 is simple and easy since you can create your own lists and manage them through SharePoint website settings. But when we start building a website under SharePoint, we need to manage and customize these lists from the code. I created a small website using Microsoft.SharePoint.dll, to manage SharePoint lists.

I created a small website that is able to read all Lists created in any SharePoint website, and allow the management of these lists, you can add, edit. delete Lists, List Items, fields…

The whole idea started when we got a task from one of our clients to post data to the SharePoint calendar automatically. So we needed a tool to allow to post any information to the SharePoint List “Calendar”.

I had to add a new column for the Calendar under the name “Assigned To” of type “User” and which will be the current logged in user in the SharePoint website.

SPSite site = new SPSite(“http://localhost:48/”);
SPWeb myWeb = site.OpenWeb();
//to enable editing from this website
myWeb.AllowUnsafeUpdates = true;
//get the Calendar SPList
SPList calendar = myWeb.Lists[“Calendar”];
//add the new item to the Calendar
SPListItem newEvent = calendar.Items.Add();
newEvent[“Location”] = “Location A”;
newEvent[“Start Time”] = DateTime.Now;
newEvent[“End Time”] = DateTime.Now.AddDays(2);
newEvent[“Description”] = “Task description goes here”;
newEvent[“Title”] = title;
SPUser user = myWeb.SiteUsers.GetByID(myWeb.CurrentUser.ID);
if (user != null)
newEvent[“Assigned To”] = user.ID;
//save the changes in the SharePoint database
newEvent.SystemUpdate();

In this way, we can add tasks for every user, and it will be automatically displayed in the SharePoint Calendar.

For more options, we can modify the Calendar View, and allow only the tasks for the current logged in User. This can be done by clicking on Modify This View option for the Calendar and we can add a new filter for this view:

Show the items when column : “Assigned To” is equal to “[Me]”

In this case any logged in user will be able to see his own Tasks.

For more information about how to manage the SPLists, you can check my article on CodeProject:

SPList Management By Code

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s