Thursday, June 30, 2011

Tuesday, June 28, 2011

Add Silverlight application in Sharepoint 2010

Microsoft SharePoint 2010 comes with an out of the box Silverlight webpart which helps to host Silverlight applications in SharePoint. For hosting the Silverlight application you need to provide the URL of the Silverlight executable in the URL property of the webpart.

You can also pass the parameters to the Silverlight application using InitParams property.

You need to implement the Silverlight application such a way that it can accept and use the InitParams, which can be consumed in Application_Start event.

private void Application_Startup(object sender, StartupEventArgs e)
IDictionary parameters = e.InitParams;
foreach (KeyValuePair parameter in parameters)
Console.WriteLine("{0} - {1}", parameter.Key, parameter.Value);

How to access SharePoint List Items using Silverlight Object Model

In the last postI introduced the Silverlight Object Model, which helps to access the SharePoint objects directly from Silverlight. In this I am posting about how to access SharePoint List Items using Silverlight Object Model. In this I am using Caml query object, which is used to get the Fields.

using Microsoft.SharePoint.Client;

private List list;
private ListItemCollection listitem;

public MainPage()

ClientContext spContext = new ClientContext("http://pct174:10972");
if (spContext != null)
List list = spContext.Web.Lists.GetByTitle("Custom List");
listitem = list.GetItems(CamlQuery.CreateAllItemsQuery());
spContext.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), new ClientRequestFailedEventHandler(OnRequestFailed));

private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
private void OnRequestFailed(Object sender, ClientRequestFailedEventArgs args)

private void FillList()
var lst = new List();
foreach (var i in listitem)
lst.Add(new listdata
Title = i["Title"].ToString(),
EmployeeName = i["Employee_x0020_Name"].ToString(),
Gender = i["Gender"].ToString(),
DOB = ((DateTime)i["DOB"])
} );
And if you don’t want all the columns or you want to specify the columns you want to access you can use Caml Query object’s ViewXml property.?

CamlQuery camlQuery = new CamlQuery();
string query = "";
camlQuery.ViewXml = query;
this.oListItems = this.oList.GetItems(camlQuery);

You can access Custom Lists and Document Libraries by this method.

Central Administration Pages

The most pages are used by Central Administration in Windows SharePoint Services 3.0 are located under 12 HiveTemplatesAdmin. The virtual location of these pages can be mentioned as SiteUrl/_admin/Page.aspx

I list out those pages in following table

Page TitleServer Relative URL LocationDescription
AddContentDatabase/_admin/newcntdb.aspxThis page used to create a new content database or to add an existing content database to this web application
AddIncomingUrl/_admin/AddIncomingUrl.aspxThis page used to add an internal url to the web application.
AlternateUrlCollections/_admin/AlternateUrlCollections.aspxThis Page list out the alternate url’s available in the farm or particular web application.
ApplicationCreated/_admin/applicationcreated.aspxThis page comes out after the creation of web application.
ApplicationManagement/_admin/applications.aspxThis page contains links to pages that help you configure settings for applications and components that are installed on the server or server farm.
AuthenticationProviders/_admin/authenticationproviders.aspxThis page list out the zone and membership providers of the web application.
Backup/_admin/Backup.aspxThis page list out the Web applications for backup.
BackupHistory/_admin/BackupHistory.aspxUse this page to manage the history logs for backup and restore operations.
BackupStatus/_admin/BackupStatus.aspxUse this page to view the backup or restore job status.
ContentDatabaseSettings/_admin/oldcntdb.aspxUse this page to manage content databases for the selected web application
CreateExternalUrl/_admin/CreateExternalUrl.aspxuse this page to create an External resource mapping.
CreateSite/_admin/CreateSite.aspxThis page used to create a new top-level Web site
DeploySolution/_admin/DeploySolution.aspxThis page has a list of the Solutions in the farm.
DspSettings/_admin/dspsettings.aspxThis page contains settings for data retrieval services.
EditOutboundUrls/_admin/EditOutboundUrls.aspxUse this page to edit the public zone URL’s of the web application
ExtendVs/_admin/extendvsoption.aspxUse this page to create a new Windows SharePoint Services application or to extend an existing application to another IIS Web Site.
FarmCredMgmt/_admin/FarmCredentialManagement.aspxUse this page to manage the service accounts in the farm.
FarmServers/_admin/FarmServers.aspxThis page has a list of the Servers in the farm.
JobEdit/_admin/JobEdit.aspxUse this page to change or delete a timer job.
ManageContentDatabases/_admin/cntdbadm.aspxUse this page to manage content databases for this web application.
Operations/_admin/operations.aspxThis page contains links to pages that help you manage your server or server farm, such as changing the server farm topology, specifying which services are running on each server, and changing settings that affect multiple servers or applications.
Owners/_admin/owners.aspxUse this page to view and change the primary and secondary site collection administrators for a site collection.
Policy/_admin/policy.aspxThis Page used to manage the Policy for the web application.
PolicyAnonymous/_admin/policyanon.aspxThis page has the Policy settings for the anonym ous users of the Web application.
PolicyRole/_admin/policyrole.aspxUse this page to add the Permission Policy level for the web application.
PolicyRoles/_admin/policyroles.aspxUse this page to manage the permission levels for the web application.
PolicyUser/_admin/policyuser.aspxUse this page to add the policy for the users in Web application.
Restore/_admin/Restore.aspxUse this page to restore from backup.
RestoreStep1/_admin/RestoreStep1.aspxUse this page to get the Backup file location of the web application.
RestoreStep3/_admin/RestoreStep3.aspxUse this page to restore the specific content from the web application.
RetractSolution/_admin/RetractSolution.aspxThis Page used to retract the solution from the web application.
RevertUpgrade/_admin/RevertUpgrade.aspxUse this page to revert back to the previous version environment.
SelectAlternateUrlCollection/_admin/SelectAlternateUrlCollection.aspxUse this page to select the alternate URL for the web application.
SelectServer/_admin/SelectServer.aspxUse this page to select the server from server collection.
SelectService/_admin/SelectService.aspxUse this page to select the service from the service collection.
SelectSite/_admin/SelectSite.aspxUse this page to select the SiteCollection from Web Application.
SelectWebApplication/_admin/SelectWebApplication.aspxUse this page to select the Web Application from the collections of Web Applications.
Server/_admin/Server.aspxThis page has the list of service from the Server.
ServiceJobDefinitions/_admin/ServiceJobDefinitions.aspxThis page has a list of the timer job definitions of the server or web application.
ServiceRunningJobs/_admin/ServiceRunningJobs.aspxThis page has a list of the timer jobs running in Web Application.
SiteCreated/_admin/SiteCreated.aspxThis page displays after the creation of SiteCollection.
Solutions/_admin/Solutions.aspxThis page has a list of the Solutions in the farm.
SolutionStatus/_admin/SolutionStatus.aspxUse this page to list the Status for the Solution of the web application.
StartBackup/_admin/StartBackup.aspxUse this page to include the content in backup of the web application.
UnextendVs/_admin/unextendvs.aspxUse this page to remove Windows SharePoint Services from an IIS Web site.
UpgradeStatus/_admin/UpgradeStatus.aspxUse this page to see the status of a timer-based upgrade.

We can see this list of pages in Microsoft.SharePoint.Administration.AdminPages internal Class from the Microsoft.SharePoint Assembly.

How to Debug a Web Part for SharePoint 2010

The basic steps are as follows:

1) Open the solution with the web part(s)
2)Copy the assembly (after it has been built) to the bin directory of the WSS web site and be sure to include the.pdb files
3) Deploy the web part (copy to the bin with the pdb as above, import the part into the web part gallery so it is visbile, create a smaple page and add the web part to the page in design view and publish the page)
4) Place a break point on the code of interest in Visual Studio
5) Under the Debug Menu, select Attach to Process
6) Find the w3wp.exe process. If none exists, begin browsing to the site that has the web part you are debugging. (I usually conduct an IIS reset so that all of the w3wp.exe processes go away and the sole one that you are interested in is easier to find)
7) Watch as the page processes and as soon as your web part is hit, Visual Studio will load symbols and begin the debugging process

Hopefully now, rather than climbing thorugh stack traces, Response.Write output, etc. you can conduct full-fidelity debugging and shave days off of a task that would only take hours.

Updating SharePoint ListItems

There are two methods available to update the List Items on SPListItem Object.

SPListItem.Update() used to update all the values in SharePoint List Item including pre-defined hidden fields. If we modified the item, that will affects the Modified Date, Modified By, Version information fields.

SPList olist = oweb.Lists.TryGetList(“ListName”);
SPListItem olistitem = olist.Items[1];
olistitem.Title = “Sample List Item”

SPListItem.SystemUpdate() method used to update the values of the listitem without modifying the Modified Date, Modified By and Version information fields.

SPList olist = oweb.Lists.TryGetList(“ListName”);
SPListItem olistitem = olist.Items[1];
olistitem.Title = “Sample List Item”

Ribbon Locations – 1 ( Document TAB )

I have searched for the Location of SharePoint Upload Ribbon button, but I haven’t got any reference for that. And finally I got the answer from ”CMDUI.XML”. So I have added the Locations and type of Controls used for SharePoint Server Ribbon Control.

For Default Server Ribbon Customization Locations, browse to .

Locations for SharePoint Server Ribbon’s Document Tab,
Control Location Control Type
Ribbon.Documents.New GROUP
Ribbon.Documents.New.NewDocument SplitButton
Ribbon.Documents.New.AddDocument Menu
Ribbon.Documents.New.AddDocument.Upload.Upload Button
Ribbon.Documents.New.AddDocument.Upload.UploadMultiple Button
Ribbon.Documents.New.NewFolder Button

Ribbon.Documents.EditCheckout GROUP
Ribbon.Documents.EditCheckout.EditDocument Button
Ribbon.Documents.EditCheckout.CheckOut Button
Ribbon.Documents.EditCheckout.CheckIn Button
Ribbon.Documents.EditCheckout.DiscardCheckOut Button

Ribbon.Documents.Manage GROUP
Ribbon.Documents.Manage.ViewProperties Button
Ribbon.Documents.Manage.EditProperties Button
Ribbon.Documents.Manage.ViewVersions Button
Ribbon.Documents.Manage.ManagePermissions Button
Ribbon.Documents.Manage.Delete Button

Ribbon.Documents.Share GROUP
Ribbon.Documents.Share.EmailItemLink Button
Ribbon.Documents.Share.AlertMe FlyoutAnchor
Ribbon.Documents.Share.AlertMe.Menu Menu
Ribbon.Documents.Share.AlertMe.Menu.Scope.AlertSelection Button
Ribbon.Documents.Share.AlertMe.Menu.ManageAlerts.ManageAlerts Button

Ribbon.Documents.Copies GROUP
Ribbon.Documents.Copies.Download Button
Ribbon.Documents.Copies.SendTo FlyoutAnchor
Ribbon.Documents.Copies.ManageCopies Button
Ribbon.Documents.Copies.GoToSourceItem Button

Ribbon.Documents.Workflow GROUP
Ribbon.Documents.Workflow.ViewWorkflows Button
Ribbon.Documents.Workflow.Publish Button
Ribbon.Documents.Workflow.UnPublish Button
Ribbon.Documents.Workflow.Moderate Button
Ribbon.Documents.Workflow.CancelApproval Button

Ribbon.Documents.QuickSteps GROUP

Ribbon.Documents.FormActions GROUP
Ribbon.Documents.FormActions.RepairItems Button
Ribbon.Documents.FormActions.RepairAllItems Button
Ribbon.Documents.FormActions.MergeDocuments Button

On Coming posts, I’ll add the Locations for Other Tabs and Groups. So Stay tuned.

Wednesday, June 15, 2011

Send an email with html format using SPUtility.SendEmail

Send an email with html format using SPUtility.SendEmail
using this Namespace
using System.Text;
using System.Collections.Specialized;

SPWeb oWeb = SPContext.Current.Web

StringDictionary headers = new StringDictionary();

headers.Add("from", "");
headers.Add("to", spUser.Email);
headers.Add("subject", "Welcome to the SharePoint group: ABC site: ");
headers.Add("content-type", "text/html"); //This is the default type

System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
strMessage.Append("Login Instructions:");
strMessage.Append("< span style='color:red; '> you are a US employee ALWAYS login in using the following login format< /span >");
SPUtility.SendEmail(web, headers,strMessage.ToString());

Best of Luck

Friday, June 3, 2011

SharePoint's "!New" Indicator

I've had a few folks ask how to alter the amount of time the “!New” icon shows up next to a recently added SharePoint list items. I believe the default timing is set to 24 hours (That is, a “new“ item is designated for the first day it is listed).

One person asked how to simply turned it off. Another asked how to extend it to a longer period so more users are aware of new content. The answer, luckily, is the same... You need to use a command line statement. The syntax is below.

Note a few thing:

1. To turn off the “!New” icon, set the number of days to zero

2. The change is for ALL list items (not just documents) on the virtual server

3. The change is immediate and does not require an IISRESET

Run the following (you may need to navigate to the directory where stsadm resides):

stsadm.exe -o setproperty -pn days-to-show-new-icon -pv ## -url [Your Virtual Server's URL]

where ## is the number of days to show the “!New“ icon

Sunday, May 29, 2011

Applying a SharePoint Designer Workflow to multiple Lists in Sharepoint 2010

When using SharePoint Designer to create a workflow you are required to bind the workflow to a particular list:

The problem is that you cannot from this interface bind the workflow to other lists.

You might be tempted to use the “Save List as Template” option in the List’s settings, and then create a new list based on this template to create a list that uses the workflow. The problem is that the workflow is still bound to the list from which the new list is based, and an error will probably be generated whenever you try to start an instance of the workflow – the steps will try to reference items etc. in the original list.

In SharePoint Designer you can expand out the files associated with a workflow:

The “.xoml.wfconfig.xml” file contains information on the list the workflow is bound to using the List’s ID (a GUID):

The file “.xoml.rules” contains the ‘conditions’ you program for the workflow and the “.xoml” file contains the ‘actions’. The “.aspx” form is displayed when the workflow is started manually.

To re-use a workflow in another list:

Create a new workflow on the new list.
Create at least one step, one condition and one action in this workflow. This ensures that the files shown above are created and they will be replaced by the next operations.
From the original workflow open the .xoml file as XML and copy the entire contents to the clipboard.
Open the .xoml file for the new workflow and replace the entire contents with the copy from (3).
Repeat this operation for the xoml.rules file.
Double click the .xoml file for the new workflow to open the workflow in the Workflow Designer and click Check Workflow to verify no errors and then click Finish to ensure the workflow is saved.

I’ve tested this technique with simple workflows and the process works well.

Thursday, April 28, 2011

Delete All Itmes in List using PowerShell

Delete All Itmes in List using PowerShell

$SITEURL = "http://spsrv:8888"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title

# Enter name of the List below
$oList = $web.Lists["Contract Expiry Alert"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
"Deleting : " + $intIndex