Tuesday, March 19, 2013

Client Object Model using C# and PowerShell


In this article we will be seeing how to create, update and delete SharePoint 2010 lists using Client Object Model (through both C# code and PowerShell script).

Assembly: Microsoft.SharePoint.Client.dll

Microsoft.SharePoint.Client.Runtime.dll

Namespace: Microsoft.SharePoint.Client
//Creating the list using Client Object Model:
// C# code:
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.Client;
namespace COM
{
    class Program    {        
        static void Main(string[] args)
        {
            string siteUrl= "http://serverName:31829/sites/Home/";
            ClientContext clientContext=new ClientContext (siteUrl);
            Web site = clientContext.Web;
            ListCreationInformation listCreationInfo = new ListCreationInformation();
            listCreationInfo.Title = "COM List";
            listCreationInfo.Description = "List created using COM";
            listCreationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
            List list = site.Lists.Add(listCreationInfo);
            clientContext.ExecuteQuery();
            Console.WriteLine("List is created successfully");
            Console.ReadLine();
        }
    }
}
// PowerShell Script:

$siteUrl="http://serverName:31829/sites/Home/"
$clientContext= [Microsoft.SharePoint.Client.ClientContext,Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]
$context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[Microsoft.SharePoint.Client.Web]$site=$context.Web;
$listCreationInfo=New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInfo.Title="COM List"
$listCreationInfo.Description="List created using COM"
$listCreationInfo.TemplateType=[int][Microsoft.SharePoint.Client.ListTemplateType]::DocumentLibrary;
[Microsoft.SharePoint.Client.List]$list=$site.Lists.Add($listCreationInfo);
$context.ExecuteQuery();
write-host "List is created successfully"
//Deleting the list using Client Object Model:
// C# code:
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.Client;
namespace COM
{
    class Program    {        
        static void Main(string[] args)
        {
            string siteUrl= "http://serverName:31829/sites/Home/";
            ClientContext clientContext=new ClientContext (siteUrl);
            Web site = clientContext.Web;
            List list = site.Lists.GetByTitle("cl");          
            list.DeleteObject();
            clientContext.ExecuteQuery();
            Console.WriteLine("List is deleted successfully");
            Console.ReadLine();
        }
    }
}
// Powershell script:
$siteUrl="http:// serverName:31829/sites/Home/"
$listName="Updated COM List"
$clientContext= [Microsoft.SharePoint.Client.ClientContext,Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]
$context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[Microsoft.SharePoint.Client.Web]$site=$context.Web;
[Microsoft.SharePoint.Client.List]$list=$site.Lists.GetByTitle($listName);
$list.DeleteObject();
$context.ExecuteQuery();
//Updating the list using Client Object Model:
//C# code:
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.Client;
namespace COM
{
    class Program    {        
        static void Main(string[] args)
        {
            string siteUrl= "http://serverName:31829/sites/Home/";
            ClientContext clientContext=new ClientContext (siteUrl);
            Web site = clientContext.Web;
            List list = site.Lists.GetByTitle("COM List");
            list.Title = "Updated COM List";
            list.Update();
            clientContext.ExecuteQuery();
            Console.WriteLine("List is updated successfully");
            Console.ReadLine();
        }
    }
}
// PowerShell Script:

$siteUrl="http://serverName:31829/sites/Home/"
$clientContext= [Microsoft.SharePoint.Client.ClientContext,Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]
$context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[Microsoft.SharePoint.Client.Web]$site=$context.Web;
[Microsoft.SharePoint.Client.List]$list=$site.Lists.GetByTitle("COM List");
$list.Title="Updated COM List"
$list.Update();
$context.ExecuteQuery();
write-host "List is updated successfully"

Tuesday, January 22, 2013

Authentication in SharePoint 2010 Classic Mode Vs Claims Based


Classic Mode:

This is nothing but Windows Authentication. If any web application is created with Classic Mode Authentication then it cannot applicable to configure forms based authentication. But, to configure this application to use Forms Based Authentication then you can convert from Classic Mode to Claims Based. 

But, there is no UI exist for doing this conversion. The only way around is through PowerShell.

$app = get-spwebapplication "URL"
$app.useclaimsauthentication = "True"
$app.Update()
But, if an application is created using Claims based and if you want to convert from Claims based to Classic Mode then it is not possible either through UI or through PowerShell. So, remember this.

Claims Based:

In SharePoint 2010 for a web application we can enable both windows, forms authentication. In earlier implementation to do this, we have to create two web applications which has different zones and different authentication. But, with the new claims based authentication a single application can have the capability to configure both windows and forms under single URL. All this is possible because of the authentication framework is built on Microsoft Identify Foundation. And it uses “Geneva” framework to handle this authentication.

Friday, June 24, 2011

SharePoint Vocabulary: Part 5

Resetting IIS
Reset IIS, or Internet Information Services--the Web server that Microsoft uses to host SharePoint. This is because configuration changes need to occur before the product can work, but the changes can't happen until IIS is reset.

There are a couple of places where you can reset IIS. The easiest way, in my opinion, is to go to Start, and in the search box that reads Search programs and files, type cmd and hit Enter. At the prompt where your cursor is, type iisreset and hit Enter. IIS automatically stops and restarts.

If you're feeling fancy (and if you have the appropriate level of administrator permissions), you can reset IIS through IIS Manager. How you access IIS Manager depends on your versions of IIS and your operating system. I found this article on IIS Manager on msdn.microsoft.com to be helpful.

IIS 7.0, Windows Server 2008: To access IIS Manager, select Start > All Programs > Accessories > Run. In the Run text box, type control panel and click OK. Click Classic View. Double-click Administrative Tools > Internet Information Services.
IIS 5.0 and 6.0, Windows XP Professional: From the Start menu, click the Control Panel. Switch to Classic View. Double-click Administrative Tools > Internet Service Manager.
IIS 5.0 and 6.0, Windows Server 2003: From the Start menu, select Administrative Tools > Internet Information Services (IIS) Manager.
IIS 5.0 and 6.0, Windows Server 2000: Select Start > Applications > Administrative Tools > Internet Service Manager.
World Wide Web Publishing Service (WWWPS)
The WWWPS lets your operating system act as a Web server. It works with IIS. Sometimes you might have to stop and start the WWWPS, like when you're upgrading to a newer version of PM Central. This is because the upgrade process replaces DLLs on the server, but if the WWWPS is on, the files are locked, and they can't be replaced during the upgrade process.

To start or stop the World Wide Web Publishing Service, you'll need the proper administrative-level permissions. Go to the Start menu and select Administrative Tools > Services. Scroll down until you see World Wide Web Publishing Service.

You can stop or start the service two ways:

Select World Wide Web Publishing Service, then scroll back up to the top and select Stop or Start the service from the options on the left.
Right-click on World Wide Web Publishing Service, then select Stop or Start.
Error Log
All of Bamboo's products have an error log. The error log is pretty self explanatory: it's where you can look for errors or problems that occurred while you were installing or configuring a product so that you can troubleshoot the problems. The error log is located on the SharePoint server in :\WINDOWS\Temp\BambooSolutions\bsc_bamboo_%processid.log.

Event Viewer
The event viewer stores information about events from the programs on your computer. The event viewer can help you troubleshoot problems or check recent updates. This article goes into more detail about what information is stored in the event viewer.

There are two ways to access the event viewer:

Selecting Start, right-clicking on My Computer, and selecting Manage > Event Viewer.
If you have Windows 7: Go to Start > Control Panel > System and Security > Administrative Settings. Double-click Event Viewer.
If you have Windows XP: Select Start > Control Panel > Performance and Maintenance > Administrative Tools. Double-click Event Viewer.
Web Page Security Validation
Web Page Security Validation puts a time limit on Web pages that are on SharePoint Services Web site when users submit information to the server. This helps improves security.

Some of Bamboo's products use Microsoft AJAX extensions, which let you do things like zoom in and out on a page or select an option from a drop-down menu. Web Page Security Validation needs to be turned on for the AJAX extensions for the product to work.

Web Page Security Validation is located in SharePoint Central Administration > Application Management > Web Application General Settings. Then scroll down the page until you see Web Page Security Validation.

SharePoint Vocabulary: Part 4

Central Administration: This is the SharePoint site where you can access administration information like permissions, an Administrator Tasks list and a farm topology. Not all users have access to Central Administration, usually just administrators and managers. Central Administration has three pages: Home, Operations and Application Management.

The Home page features a quick view of what needs to be completed in the Administrator Tasks list as well as other information.
The Operations page lets you determine settings that impact the entire farm. You set up e-mail here.
The Application Management page is where you set up and monitor Web Applications and site collections.

Global Assembly Cache (GAC): The GAC is a folder on the server that's hosting SharePoint. .NET assemblies (.exe and .dll) are stored here for Web Parts and services.

Load balancing URL: This is the domain name for sites that users access in the SharePoint Web Application, or what all of your links on your SharePoint server are prefixed with. For example, when I named the SharePoint site on my virtual PC, I named it "katievpc," so all of my links in SharePoint on my virtual PC begin with http://katievpc. Which is unfortunate because everyone else named their load balancing URLs "moss," like http://susanmoss. Sigh. Another misstep for me.

Out of the box: This just means that a software product or program hasn't been customized or enhanced; it's being used just with whatever features the product came with.

SMTP, or Simple Mail Transfer Protocol: The standard protocol for e-mail on the Internet. It determines the format of the message and the message transfer agent. The message transfer agent stores and forwards the e-mails. Your e-mail client "talks" to the SMTP server to get e-mail from one place to another. You have to set up the SMTP in SharePoint so you can use SharePoint to e-mail people.

Timer job: Some applications need timer jobs to run and perform specific tasks. You can also create your own timer jobs to do scheduled tasks in the Central Administration site by clicking Operations and then Timer Job Definitions.

UAC, or User Account Control: Available on Windows Vista and Windows Server 2008, the UAC manages user accounts. It lets users run their computers as regular users instead of administrators, which is a good thing because computers are more secure if they are running with fewer privileges. An example of UAC is when you see a popup box that reads, "Do you want to allow the following program to make changes to this computer?" after you click on an application

SharePoint Vocabulary: Part 3--What is SharePoint?

A good way to think about SharePoint is as a group of technologies. In this group, the main component is Windows SharePoint Services (WSS). You can't have any other part of SharePoint if you don't have WSS.

WSS is an ASP.NET 2.0 Web application. (ASP.NET builds Web applications, and it's used to customize SharePoint.) When you install WSS, you also have to install ASP.NET, which needs several things to run:

IIS version 6 or 7: Internet Information Services is the Web server that hosts SharePoint

.NET Framework version 2.0 and 3.0: This software set installs ASP.NET and Windows Workflow Foundation (WF). (WF lets users create workflows in applications that are written for Vista, XP and Windows Server 2003 operating systems.)

SQL Server 2000 or later:Microsoft's database management system
and Windows Server 2003 or later: Microsoft's server operating system.
All of the SharePoint technologies use the services that WSS provides, particularly Microsoft Office SharePoint Server (MOSS) 2007. These services include content management, data storage, security, management, services and more. MOSS builds on these services to provide:

core services like business data catalog, Excel services and personalization
application services like dashboards and workflows
portals
people and personalization
and more.

SharePoint Vocabulary: Part 2

Application Pool: A group of URLs that define a set of Web applications that are sharing one or more worker processes. Application pools are an easy way to administer a set of Web sites and Web applications and the processes of each. Application pools help improve the reliability and manageability of a Web infrastructure. They are managed in the IIS (Internet Information Services) manager.

Assembly: In the .NET framework, an assembly is a partially compiled code library that's used in deployment, versioning and security. Assemblies come in two forms: process assemblies (.exe) and library assemblies (.dll). Assemblies can contain more than one file or code module.

CAML, or Collaborative Application Markup Language: An XML-based markup language that's used in SharePoint. It contains specific tags that define and display data, sites and lists. It is case sensitive.

Code Library: A collection of code that provides services to specific programs or operating systems.

Code Module: A file containing instructions in code.

Deploy: Installing and running a product or program.

DLL, or Dynamic-Link Library: An executable program module in Windows. At runtime, a DLL performs one or several functions.

DWP: The file extension for a Web Part.

MOSS 2007, or Microsoft Office SharePoint Server 2007: MOSS 2007 uses the services in WSS, but it also adds its own services, creating applications such as Business Intelligence, People and Personalization, Enterprise Content Management and Portals.

REST, or Representational State Transfer: An XML-based protocol for calling Web services over HTTP.

SOAP, or Simple Object Access Protocol: Another XML-based protocol, SOAP is message based and accesses services on the Web. It uses HTTP to send text commands across the Internet.

Versioning: When a software product is upgraded or improved, it gets a new name or a number assigned to that version of the product to help identify which version it is. So if you have a product called the Data Compiler, the original version is named 1.0, and minor versions of the product are 1.3, 1.5 and 1.8, while a major version is called 2.0.

Worker Process: Microsoft uses this term to describe a windows process that runs Web applications. The process also handles requests sent to a Web server about a specific application pool.

SharePoint Vocabulary Part1

APIs, or Application programming interfaces: APIs are what let you do everything that you can do in the SharePoint user interface, like creating new sites or workspaces, uploading photos or documents, and creating tasks and alerts.

ASP.NET: Microsoft's platform for building Web applications. It's used to customize SharePoint.

Child: This term helps show hierarchy within SharePoint, specifically within sites. A child site is a subsite of the top-level, or parent, site.

Farm, or server farm: A group of servers that share the same administrative tools and are part of the same organization or group.

IIS, or Internet Information Services: The Web server that Microsoft uses to host SharePoint. It runs on Windows Server 2003.
Edited to add: IIS doesn't necessarily run on Windows Server 2003. There are different versions of IIS depending on the operating system you have, such as Windows XP or Windows 2008. So for example, IIS 7.0 runs on Windows Server 2008, and IIS 6.0 runs on Windows 2003.

Library: Sites have libraries, which store data. The most common library in SharePoint is the document library, but you can use libraries to store any kind of files or data.

List: A table of data that is stored in a site. Lists help provide data like tasks, discussions and links.

.NET Framework: Versions 2 and 3 of this set of software installs ASP.NET and Windows Workflow Foundation (WF).

Parent: This term helps show hierarchy within SharePoint, specifically within sites. A parent site is the top-level site; it can have one or several children, or subsites.

Site: In SharePoint, sites are the building blocks, where users can share data in lists and libraries or view and edit Web Part pages. They're created for a specific purpose, so for example, a company may create an HR site, an Accounting site and a Project Management site.

Site Collection: A site collection is a group of sites that are related. These sites have the same owner and administration settings. Site collections have a hierarchy; there's always at least one top-level site in a site collection, with subsites underneath. Every Web application contains at least one site collection.

SQL Server 2000 (or later): Microsoft's database management system.

User Interface: The part of SharePoint that you see and interact with. (It's what appears on your monitor screen.)

Web applications: They provide services, as opposed to Web sites, which typically just display information. Web applications are Web sites that run on IIS. They help create a company's information environment. They are hosted on the Web server.

Windows Server 2003 (or later): Microsoft's server operating system.