Tuesday, May 25, 2010

SharePoint 2010 PowerShell Commands

I was playing with some PowerShell Commends. Suddenly came to my mind, how to get the whole SharePoint 2010 related PowerShell Commands. Simple as given below. smile_wink
Open the PowerShell Window (aka SharePoint 2010 Management Shell), type the command…

Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” | select name, definition | format-list > C:\SP2010_PowerShell_Commands.txt

image

Have fun with PowerShell.

Thursday, May 13, 2010

SharePoint 2010 for Developers

Today the 13th May, I did another successful presentations with demos on “SharePoint 2010 for Developers” at dotNetForum monthly session. Actually it’s a very special day to all the techies as 12th was the Global Launch of Office 2010 and SharePoint 2010.
Though it was bit warm without the air condition, there were over 100 attendees. In the two hour session I covered 3 main topics.
. What’s new in SharePoint 2010 (for Developers)
. Visual Studio 2010 tools for SharePoint
. Deploying SharePoint 2010 Web Parts.
With the time constraints, I was unable to cover the 4th topic, “Deploying SharePoint 2010 Workflows”.
13th May dotnetforum
My sincerer thanks to all the participants and special thanks to Jinath and Wela.

Business Process Automation with SharePoint and Workflow Foundation

Yeah, I know I’m late on this too. smile_wink On Friday the 7th May 2010 at ANC auditorium I hosted a workshop on “Business Process Automation with SharePoint and Workflow Foundation. Actually it was my 1st workshop (Free of charge) at NetAssist, a nice crowd of over 90 participants were attended.
This workshop targeted both the Business users as well as the technical users. Started with an introduction to SharePoint 2007, followed by InfoPath 2007 forms and Workflow on SharePoint Designer and OOB Workflows. I’m happy as the Q&A session too went very well, many questions came from the business users. Photos after the brake. Thanks everybody who attended.
IMG_0465 IMG_0466 IMG_0468IMG_0469IMG_0471IMG_0472

Wednesday, May 12, 2010

SharePoint 2010 and Office 2010 Global Launch

Are you ready for the BIG DAY? SharePoint 2010 and Office 2010 Global Launch. Watch the keynote done by Stephen Elop, President of the Microsoft Business Division, join the virtual launch conversation, and participate in on-demand sessions where you’ll learn more about how Microsoft products can solve the unique productivity challenges you’re facing as you look to the future.


Keynote is focused on...
  • Deliver maximum productivity across PC, phone, and browser
  • Enhance IT choice and flexibility
  • Leverage a platform for developers to build innovative solutions

Tuesday, May 11, 2010

Microsoft SharePoint 2007 Development – Fun with Lists

List Management

List is more like a Table in a Database. Of all the tasks a SharePoint programmer can do in SharePoint, working with Lists is the mostly common task.
Namespace: Microsoft.SharePoint
Classes: SPList, SPListItem, SPListItemCollection

With MOSS 2007 and WSS, we get different kinds of lists. To name them…
. Announcements list
. Contacts list
. Discussion Board list
. Links list
. Calendar list
. Tasks list
. Project Tasks list
. Issue Tracking list
. Survey list
. Custom list
. Custom list in Datasheet view
. KPI list (SharePoint Server 2007 only)
. Languages and translators (SharePoint Server 2007 only)
. Import spreadsheet
This article doesn’t cover what SharePoint is or its usage. Targeted audience is the programmers who are already familiar with SharePoint who’s looking for a programming introduction to Lists in SharePoint and leverage the features of SPList and SPListCollection classes in SharePoint Object Model.

Enumerating Lists
Yes you see it right, its Lists. Before getting to the list items, let’s try to get a collection of lists implemented in a site. So basically in other words we are trying to enumerate through any SPListCollection instance.
First we need to create a SPSite object and get all webs in to a SPWeb object by calling the AllWebs() method of the SPSite object. Then it’s just a matter of iterating through the SPLists objects available in the SPWeb object.
Create a new C# console application and paste the code below changing the SPSite class’s input parameter url.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;

namespace AllLists
{
class Program
{
static void Main(string[] args)
{
SPSite site = new SPSite("http://dc:8844");
SPWeb web = site.AllWebs[0];
foreach (SPList list in web.Lists)
{
Console.WriteLine("{0}{1} - {2} items.",
list.Hidden ? "*" : "",
list.Title, list.ItemCount);
Console.WriteLine("Created by {0}", list.Author.Name);
Console.WriteLine("{0}", list.Description);
Console.WriteLine("................................");
}
Console.WriteLine("\n{0} lists found.", web.Lists.Count);
Console.ReadKey();
}
}
}
image 

Enumerating list items in Lists

It is the SPList you have to iterate through to find the SPListItem. But you might run in to some errors if you do the list iteration against a top level site collection instead of a team site.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;

namespace AllLists
{
class Program
{
static void Main(string[] args)
{
SPSite site = new SPSite("http://dc:8844/sales/");
SPWeb web = site.AllWebs[0];
foreach (SPList list in web.Lists)
{
Console.WriteLine("{0}{1} - {2} items.",
list.Hidden ? "*" : "",
list.Title, list.ItemCount);
Console.WriteLine("Created by {0}", list.Author.Name);
Console.WriteLine("{0}", list.Description);
Console.WriteLine("------------------------");
foreach (SPListItem item in list.Items)
{
Console.WriteLine("\t * {0}", item.Title);
}
Console.WriteLine("\n");
Console.WriteLine("................................");
}
Console.WriteLine("\n{0} lists found.", web.Lists.Count);
Console.ReadKey();
}
}
}

Make sure you add reference to Microsoft.SharePoint.dll assembly prior writing the code above.

Managing Lists

When working with Lists, the source container is always an object created from SPListCollection. Given code give below, I create two Task Lists, selecting the “Task” template.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;

namespace ManagingLists
{
class Program
{
static void Main(string[] args)
{
SPSite rootSite = new SPSite("http://dc:8844");
SPWeb rootWeb = rootSite.AllWebs[0];

SPListTemplate sourceTemplate = rootWeb.ListTemplates["Tasks"];
Guid newListGuid = rootWeb.Lists.Add("My First Task List",
"My First Task List", sourceTemplate);
Guid secondNewListGuid = rootWeb.Lists.Add("My Second Task List",
"My Second Task List", sourceTemplate);
SPList newList = rootWeb.Lists[newListGuid];
SPList secondNewList = rootWeb.Lists[secondNewListGuid];
secondNewList.Delete();
newList.Description = "My Custom Task List - From Code";
newList.Update();
Console.WriteLine("List creation completed.");
Console.ReadLine();
}
}
}

Browse your SharePoint site, where you could see both the Task Lists you created using code above.

Managing List Items

Managing List Items is same as managing Lists. Okay, let’s add a task item in to task list in code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace ManagingListItems
{
class Program
{
static void Main(string[] args)
{
SPSite rootSite = new SPSite("http://dc:8844");
SPWeb web = rootSite.AllWebs[0];
SPList taskList = web.Lists["My Task List"];
SPListItem newTask = taskList.Items.Add();
newTask["Title"] = "My Task List Title";
newTask["DueDate"] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now.AddDays(30));
newTask["PercentComplete"] = 0.1;
newTask.Update();

newTask = taskList.Items.Add();
newTask["Title"] = "This Task will be deleted.";
newTask.Delete();
taskList.Update();

Console.WriteLine("Work completed.");
Console.ReadLine();
}
}
}

Summary
The SharePoint object model is so powerful that you have the full control over each and every component SharePoint provides. This article provides you an entry point to accessing and managing SharePoint Lists in code.