About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, December 31, 2008

Change the user data in "CCF session control"

Add the following code inside the button_Click event in the hosted windows application

Context objContext = new Context();

// CustomerFirstName is the property name that use to identify customers' first name

objContext["CustomerFirstName"] = "Now my name is chanaka";
ContextEventArgs contextEventArgs = new ContextEventArgs(objContext);

Wednesday, December 10, 2008

CCF Tips

Problem--> "Configuration has encountered a problem while trying to access the Configuration web service. The HTTP request is unauthorized with client authentication scheme"

Reason --> The user doesn't have enough permissions to access the inbuilt websites

Solution --> (1) Go to the 'C:\Inetpub\wwwroot'
(2) Open the web.config file of each website
(3) Change the access write to authorized users


Problem--> "C:\Program Files\Support Tools> httpcfg set urlacl /u http://+:1000/ /a D:(A;;GX;;;s-1-5-21-3811445897-853718750-2640504884-1107) returns 1332 other than 0"

Reason --> The Operating system is not 32 bit

Solution --> (1)Go to http://www.microsoft.com/downloads/details.aspx?FamilyID=96A35011-FD83-419D-939B-9A772EA2DF90&displaylang=en
(2) install this if you are using 64bit Server version


Monday, December 8, 2008

What is Customer Care Framework

Customer Care Framework is well known as CCF. This is not a really new technology. But now this is coming with new features with release of CCF 3.0. The CCF is consists of many components like Admin Console, Adapter Manager, Web Services + Multi Channel Services. All these are integrated with Agent Desktop. This helps agents to work in a efficient manner with less stress. The integration capability is expanded to Sharepoint, Biztalk & all other business applications.

Wednesday, November 26, 2008

Deploy .Cab Solution Webpart into sharepoint

(1) Open the command prompt
(2) Change the path to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin
(3) run the stsadm command to deploy the cab file
stsadm -o addwppack -globalinstall -force -filename C:\SearchWebPart_CSharp.cab

(4) Go to sharepoint site's webpart gallery
(5) Go --> New and populate the webpart
(6) Add the webpart into your page :)

Monday, November 24, 2008

Sending an Email Using .NET

private void sendingEmail(string pstrSendingEmails)
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("irononechanaka@gmail.com", "password1");

string strEmails = "sahanganepola@yahoo.com";

mail.Subject = "Email from workflow ";
mail.From = new System.Net.Mail.MailAddress(strEmails);
mail.IsBodyHtml = true;
mail.Body = "hi dear friend";

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
catch (Exception ex)


Friday, October 31, 2008


It's time to move from sharepoint to workflow engine. Actually i have to combine these 2 technologies.

WORKFLOW FOUNDATION (WF) has 2 main areas
(1) WCF(Windows Communication Foundation)
(2) WPF(Windows Presentation Foundation)

when design the workflow it has 3 approaches
(1) No-Code (using Sharepoint Designer)
(2) Code (Using VS++++++)
(3) Code-beside (combination of above methods)

The WF came up with many advanced concepts like,

So many will come soon... :)

Programatically Add a WORKFLOW to a SPList

private void setWorkflow()
SPWeb web = site.RootWeb;
SPList refList = web.Lists["DepartmentDetails"];

SPWorkflowManager wfManager = site.WorkflowManager;
SPWorkflowTemplateCollection wfTemplates = wfManager.GetWorkflowTemplatesByCategory(web, null);
string test = wfTemplates[0].Name;
test = wfTemplates[1].Name;
test = wfTemplates[2].Name;
test = wfTemplates[3].Name;
test = wfTemplates[4].Name;
SPList taskList = web.Lists["Tasks"];

Guid WorkflowHistoryGuid = web.Lists.Add("HistoryOfWorkflow", "description History", SPListTemplateType.WorkflowHistory);
SPList HistoryList = web.Lists[WorkflowHistoryGuid];
//SPList HistoryList = web.Lists["HistoryOfWorkflow"];

SPWorkflowTemplate wfTempl = wfTemplates.GetTemplateByName("Approval", CultureInfo.CurrentCulture);
SPWorkflowAssociation wfAssocite = SPWorkflowAssociation.CreateListAssociation(wfTempl, wfTempl.Name, taskList, HistoryList);

wfAssocite.AutoStartCreate = true;
catch (Exception ex)

Wednesday, October 29, 2008

Working With SPList & CAML Queries

SPWeb web = site.RootWeb;
SPList refList = web.Lists["refLstAAProgress"];
query = new SPQuery();


query.Query= "<Where><And><Eq><FieldRefName='colFormName' /><Value Type='Text'>" + pFormName +"</Value></Eq><Eq><FieldRef Name='colGroup'/><Value Type='Text'>"+ pGroupName+"</Value></Eq></And></Where>";


//query.Query= "<Where><Eq><FieldRef Name='SystemName'/><ValueType='Text'>" + pstrSystemName + "</Value></Eq></Where>";

SPListItemCollection collec = refList.GetItems(query);


if (collec!= null && collec.Count > 0)


SPListItem itemEdit = collec[0];

itemEdit["colIsDone"]= "True";

web.AllowUnsafeUpdates= true;



web.AllowUnsafeUpdates= false;



SPWeb web = site.RootWeb;

web.AllowUnsafeUpdates = false;
refList = web.Lists["refLstStageTracking"];
newListItem =logginList.Items.Add();
newListItem["Title"] ="GOGOGO";
newListItem["colFormName"] =pFromName;
newListItem["colStage"] = pStage;

newListItem["colLoginName"] = pLoginName;


Thursday, October 23, 2008

Enable Search In Sharepoint Easily

1) Go to CURRENT Web application through Central Administration

2) Create a site collection using "SEARCH CENTRE WITH TABS" under ENTERPRISE tab

3) Name as "SearchSiteChanaka"

3) Go to the CURRENT site

4) Go to all site settings

5) Search settings --> set as /sites/SearchSiteChanaka/Pages/

6) When user click he will be redirected to the search result page J

One small thing that you have to do now...

Go to

7) SSP

8) then go to 'Search settings'

9) Click on 'Content sources and crawl schedules'

10)Set incremental or full crawl

Now that's all


Friday, October 17, 2008

MySite Creation Programatically

ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new UserProfileManager(context);

foreach(UserProfile userProfile in

string userName =userProfile[PropertyConstants.AccountName].Value.ToString();

personal site for user : "
+ userName);

personal site for user : "
+ userName);

SPSite personalSite = userProfile.PersonalSite;

using(SPWeb web = personalSite.OpenWeb())

SPListTemplateType templateType = SPListTemplateType.PictureLibrary;
listId = web.Lists.Add(ConfigurationInfo.PhotoLibraryDisplayName,null, templateType);

SPList PhotoLibrary = web.Lists[listId];
PhotoLibrary.Description = "This is a picture library to show photos";

PhotoLibrary.Title= ConfigurationInfo.PhotoLibraryDisplayName;
PhotoLibrary.OnQuickLaunch= true;

web.AllowUnsafeUpdates = true;




catch(Exception ex)

.LogDebug("error while creating MySite :" + ex.Message);

Create Sharepoint People Picker Programatically

protected override void CreateChildControls()
PeopleEditor peoplePick = new PeopleEditor();
peoplePick.AllowEmpty = true;
peoplePick.AllowTypeIn = true;
peoplePick.BrowseButtonImageName = "Search";
peoplePick.CheckButtonImageName = "Validate User";
peoplePick.ErrorMessage = "No Names Found";

Friday, October 10, 2008

use of Singleton Pattern

The use of the singleton pattern is, it creates only one instance. First tme it will create an instance, but when the next call it will return the current instance, not create new instance.

Practical Example:- Normally a user can’t get two credit cards from same bank

public sealed class Logger


static Logger instance=null;

static readonly object padlock = new object();

private TextWriterTraceListener listener;

public void Create(string filename)


if (listener == null)


listener = new TextWriterTraceListener(filename);






public void WriteLog(string message)




public static Logger Instance




lock (padlock)


if (instance==null)


instance = new Logger();


return instance;





Create A Web Application Using Commands

Here you have to download the Extension of the STSADM + Have to deploy the solution to the farm........
Because the
gl-createwebapp is a new feature!!!!!

stsadm -o gl-createwebapp
-url "http://testwebapp"
-directory "c:\moss\webs\testwebapp"
-port 80
-ownerlogin "domain\user1"
-owneremail "someone@example.com"
-databasename "SharePoint_TestWebApp"
-sitetemplate "SPS#0"
-description "SharePoint_TestWebApp_80"
-sethostheader testwebapp -apidname "AppPool1"
-apidtype configurableid
-apidlogin "domain\user2"
-apidpwd "password" -timezone 10

Monday, October 6, 2008

Importance of SSP(Shared Services Provider)

The application node hosts the logical layer of sharepoint. This is also called Shared Services Provider.
It consists of many functions
(1) Index Service [also called CRAWLING]
(2) Query Service
(3) Profile Management
(4) Content Management
(5) Audience Management
(6) Business Data Catalog
(7) Excel Services
(8) Form Services [deal with INFOPATH]
(9) Job Scheduling
(10)Usage Reporting

this is a list of functions that are coming with SSP.
have a fun of ........

Sunday, October 5, 2008

Add a OOB webpart programatically in to a page

Add a webpart programatically in a easy manner

I tried to find out a method to add OOB webparts directly into a page.
Today I managed to do it!!!!!!!

is very useful if we are going to add Events, Forum(Discussion
board), Tasks list into our page with the OOB features.

using(SPLimitedWebPartManager wpm =web.GetLimitedWebPartManager(siteMapPage.Url,


//am creating a Task list

Guid WorkflowHistoryGuid = web.Lists.Add(ConfigurationInfo.Tasks, ConfigurationInfo.Tasks,SPListTemplateType.Tasks);

SPList TaskList = web.Lists[ConfigurationInfo.Tasks];

TaskList.OnQuickLaunch = true;

work starts

ListViewWebPart webPart = new ListViewWebPart();
taskList = web.Lists[ConfigurationInfo.Tasks];
viewMyTasks = taskList.Views[“My Tasks”];
viewMyTasks.DefaultView = true;


webPart.ListName = taskList.ID.ToString("B").ToUpper();

webPart.ViewGuid = taskList.DefaultView.ID.ToString("B").ToUpper();
wpm.AddWebPart(webPart,"MiddleRightZone", 2);


Monday, September 29, 2008

VSTS 2010 your ultimate tool

Today i had a chance to look about the VSTS 2010....
It's going to be the next revolution in the programming world....

It will be consists of
(1) Discover and identify existing code assets and architecture with the new Architecture Explorer.
(2) Design and share multiple diagram types, including use case, activity and sequence diagrams.
(3) Improve testing efforts with tooling for better documentation of test scenarios and more thorough collection of test data.
(4) Identify and run only the tests impacted by a code change easily with the new Test Impact View.
(5) Enhanced version control capabilities including gated check-in, branch visualization and build workflow.

There will be so many features...
The best chance that you are getting with the VSTS is, it manage all the things from the design phase to the deployment phase...
be ready with new VSTS 2010

Sunday, September 28, 2008

Add Sharepoint OOB SummaryLinkWebPart Programatically

protected override void CreateChildControls()



//EnterpriseAnnouncement webpart

web = SPContext.Current.Web;
enterpriseNoticeList = web.Lists[EnterpriseNoticeBoardUrlName”];
query = new SPQuery();
collection = enterpriseNoticeList.GetItems(query);

if(collection != null)

announcementWP = new SummaryLinkWebPart();
announcementWP.Title = ConfigurationInfo.AnnouncementsListDisplayName;
int counter = 0;

foreach (SPListItem item in collection)

(new SummaryLink(item["Title"].ToString()));

announcementWP.SummaryLinkValue.SummaryLinks[counter].LinkUrl = http://www.google.lk;

announcementWP.SummaryLinkValue.SummaryLinks[counter].OpenInNewWindow = true; announcementWP.SummaryLinkValue.SummaryLinks[counter].Description = item["Comments"].ToString(); announcementWP.SummaryLinkValue.SummaryLinks[counter].Style = "Image on left";
announcementWP.SummaryLinkValue = announcementWP.SummaryLinkValue;


catch(Exception ex)







catch(Exception ex)



Common SHAREPOINT errors.......

When you are working with sharepoint... you will get common errors...
if you are aware you can resolve it easily.....

*** have you ever got a error like this....
-------> this is because of an strange character in your item. this can be a image name, file name or template name....
-------> go through the names of the items and change the names with the conventions

Friday, September 26, 2008

Modify And Add OOB webpart into your SHAREPOINT..programatically

This is very nice....
You can add any default webpart with your modification into the webpart zone programatically.
(Am using TableOfContents.webpart to show the site map of your sharepoint site...)

using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(siteMapPage.Url, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
#region Creating SiteMap Web Part
SPList wpGallery = site.GetCatalog(SPListTemplateType.WebPartCatalog);
foreach (SPListItem item in wpGallery.Items)
if (string.Compare(item.Name, "TableOfContents.webpart", true,
CultureInfo.InvariantCulture) == 0)
SPFile wpFile = item.File;
string errorMessage = String.Empty;
XmlReader reader = XmlReader.Create(wpFile.OpenBinaryStream());
TableOfContentsWebPart tocWP = new TableOfContentsWebPart();
tocWP = (TableOfContentsWebPart)wpm.ImportWebPart(reader, out errorMessage);
tocWP.ID = "wpTableOfContents";
wpm.AddWebPart(tocWP, "MiddleRightZone", 1);
tocWP.Title = "SiteMap Dialog";

// Initialize some properties on the web part
tocWP.AllowClose = false;
tocWP.AllowEdit = true;
tocWP.AllowHide = false;
tocWP.AllowZoneChange = false;
tocWP.AllowMinimize = false;
tocWP.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;


Wednesday, September 24, 2008

Sharepoint --- Change the default view programatically

I had a requirement to change the default view programatically...
I tried so many code snippets, but it didnt work...
Finally i got the treat...

SPView myNewDefaultView = myList.Views["MyNewView"];
myNewDefaultView .DefaultView = true;
myNewDefaultView .Update();

its really good to set
rootWeb.AllowUnsafeUpdates = true;
before you try this...

Tuesday, September 23, 2008

Create a folder inside your SHAREPOINT list or document library

public static void CreateFolder(SPWeb rootWeb, SPList eLibrary, string strFolderName)
using (rootWeb)
rootWeb.AllowUnsafeUpdates = true;
SPFolderCollection folders = rootWeb.GetFolder(eLibrary.RootFolder.ServerRelativeUrl).SubFolders;
SPFolder newFolder = folders.Add(strFolderName);
catch(Exception ex)
Logger.LogWarning("Error configuring ELibrary Folder: " + ex.Message);

Wednesday, September 17, 2008

Create a SHAREPOINT site collection & subsites programatically

SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://dev3:10131"));
SPSiteCollection siteCollections = webApplication.Sites;
siteCollections.Add("http://dev3:10131/IntranetMOSS", "chanaka_temp", "chanacse@gmail.com");
catch(Exception ex)
// log the error

// Add subsites into the siteCollection
using (SPSite mySite = new SPSite("http://dev3:10131/IntranetMOSS"))
using (SPWeb myWeb = mySite.OpenWeb())
{ //path name
SPWeb newWeb = myWeb.Webs.Add("SBU", "SBU's", "Add for commercial purpose", 1033, "STS#1", false, false);
newWeb = myWeb.Webs.Add("Newss", "News", "Update with the ", 1033, "STS#1", false, false);
newWeb = myWeb.Webs.Add("Groups", "Groups", "As a unit", 1033, "STS#1", false, false);
newWeb = myWeb.Webs.Add("CorporateNews", "Corporate News", "All you need", 1033, "STS#0", false, false);
newWeb = myWeb.Webs.Add("Services", "Services", "Always with you", 1033, "STS#0", false, false);
newWeb = myWeb.Webs.Add("UserManuals", "User Manuals", "Help", 1033, "STS#0", false, false);

// you can set the breadcrumb of the each site through the code also
// Simple task.........

SPSite ChildSite = new SPSite(web.Url);
SPWeb DChildWeb = ChildSite.OpenWeb();
SPNavigationNode ParentNode = new SPNavigationNode(parentWeb.Title, parentWeb.Url + "/HomePage.aspx", true);
SPNavigationNode ChildNode = new SPNavigationNode(DChildWeb.Title, DChildWeb.Title + "/HomePage.aspx");
web.Navigation.UseShared = true;
catch (Exception ex)
// log this error

Create a webpart using Visual Studio

This is an old method, but i think this will be useful if someone has very basic knowledge.
User can add a usercontrol & any code can be in your usercontrol

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace UCAddSubjectNewsWebpart
public class UCAddSubjectNews : WebPart
UserControl usercontrol;
protected override void Render(System.Web.UI.HtmlTextWriter writer)

protected override void CreateChildControls()

Saturday, September 6, 2008

Install a feature into sharepoint

1) Open Visual Studio Command Promt

2) Navigate to 12 hive folder
a. cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

3) stsadm –o installfeature – name myFeature

4) Activate the feature by using the site settings --> site administration --> site features --> Click activate button of myFeature (new feature)

When you create a Document Management System

Factors that should be considered before make a document library (SharePoint)
1) Types of document that we are going to store (upload)
2) Templates that we are going to use
3) Metadata that associated with the documents
4) Access control
5) Policy of the documents
6) Conversion of documents (if needed in future)
7) Ability to move documents away from the document library

Most of these features can be done by using the OOB features
1) Permission setting of the document libraries
2) Target audience of the document libraries
3) Select main type of the document that we are focusing on library

How to plan the document library
1) Define the roles
2) Estimate the usage of documents
3) Organize the document
4) Content types (metadata, features, properties)
5) Content control
6) Workflows
7) Policy management

Thursday, August 28, 2008

Add a flash material into sharepoint site

1) First go to the site & Click Edit page
2) Then Add a content editor to the page
3) Click Source Editor
4) Add following Code

WIDTH="550" HEIGHT="400" id="myMovieName">

NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"

Tuesday, August 26, 2008

Add users programmatically into a SHAREPOINT cutomlist(VERY RARE)

private string setAssignedPeopleStirng(string pstrIDS)
string[] strArrNames = pstrIDS.Split(new char[] { ';' });
string strSend = string.Empty;
SPWeb web = MySite.AllWebs[WebSite];
SPUserCollection MLUserGroup = web.SiteUsers;
for (int count = 0; count <>
string strusreName = MLUserGroup.GetByID(int.Parse(strArrNames[count])).Name;
strSend += strArrNames[count].Trim() + ";#" + strusreName + ";#";
return strSend;
return string.Empty;

Wednesday, August 20, 2008

Active directory acces to get Telephone number

public Hashtable getUserTelephoneNumbers()
Hashtable arrNames = new Hashtable();
int count = 0;
string domain = "";
DirectoryEntry de = new DirectoryEntry("LDAP://" + domain);
de.Username = "MS\\Administrator";
de.Password = "password";
DirectorySearcher ds = new DirectorySearcher(de);

ds.Filter = "(&(objectClass=user)(objectCategory=person))";

ds.Sort.Direction = System.DirectoryServices.SortDirection.Ascending; ds.SearchScope = SearchScope.Subtree;
ds.PageSize = 4000;

SortedList objSortedList = new SortedList();

foreach (SearchResult result in ds.FindAll())

DirectoryEntry deTemp = result.GetDirectoryEntry();



arrNames.Add(deTemp.Properties["cn"].Value.ToString(), deTemp.Properties["TelephoneNumber"].Value.ToString());


catch (Exception ex)



catch (Exception ex)

return arrNames;


return null;



Get E-mails of all users in a SPGroup

SPWeb web = site.AllWebs

SPGroup group = web.Groups[0];
SPUserCollection MLUserGroup = web.SiteUsers;
String strUserGroupName = MLUserGroup.GetByID(27).Groups[0].Name

Tuesday, August 5, 2008

CAML query with a filter between DateTime's

SPQuery query = new SPQuery();

query.Query = "<Where><And><Geq><FieldRef Name="Created" /><Value Type="DateTime" IncludeTimeValue='FALSE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(ddtStartDate) + "</Value></Geq>" +

"<Leq><FieldRef Name="Created" /><Value Type="DateTime" IncludeTimeValue='FALSE'>" +

SPUtility.CreateISO8601DateTimeFromSystemDateTime(ddtEndDate) + "</Value></Leq></And></Where>";

SPListItemCollection collection = list.GetItems(query);<Query>

<Where> <Eq> <FieldRef Name="CatalogItem" LookupValue="TRUE" /> <Value Type="Lookup">Value Goes Here</Value> </Eq> </Where> </Query> <where> <eq> <fieldref name="PersonFieldName"/> <value type="User">User Display Name</value> </eq> </where>

Thursday, July 24, 2008

System.Diagnostics.StackTrace lobjStack = new System.Diagnostics.StackTrace();

//Get the immediate caller

System.Diagnostics.StackFrame lobjCaller = lobjStack.GetFrame(1);

System.Reflection.MethodBase lobjMethodBase = lobjCaller.GetMethod();

string lstrCallingModule = lobjMethodBase.ReflectedType.FullName;

return lstrCallingModule; // this will return the name of the class

// you can use this to get function name also

Tuesday, July 15, 2008

Dynamically Creating a CustomList, With Lookup field

private void setAlist()




SPWeb web = site.AllWebs[ConfigurationManager.AppSettings["WEB_SITE"].ToString()];

web.AllowUnsafeUpdates = true;

SPList oldList = web.Lists["Subject"];

System.Guid oldGuid = oldList.ID;

System.Guid id = web.Lists.Add("ChanakaNEW", "", SPListTemplateType.GenericList);

SPList MCQList = web.Lists["ChanakaNEW"];

System.Guid iddd = MCQList.ID;

web.Lists[iddd].Fields.Add("StudentID", SPFieldType.Text, true);

web.Lists[iddd].Fields.Add("Marks", SPFieldType.Number, false);


//web.Lists[iddd].Fields.Add("Trying", oldGuid, false);

foreach (ListItem listOf in listNames)


SPList newList = web.Lists["ChanakaNEW"];

SPListItem newListItem = newList.Items.Add();

//if ((!IsExist(name)) && (!name.Equals(string.Empty)))


newListItem["StudentID"] = listOf.Text;

newListItem["Marks"] = 3;

newListItem["Try"] = int.Parse(listOf.Value);





catch(Exception ex)





Monday, June 23, 2008

In share point you can add any feature as your wish,through a webpart.
(1) Create a website using VS
(2) Add a webuser control into it
(3) Add your logic into usercontrol functions
(4) Copy the .ascx & .cs file
(5) Paste in a separate folder
(6) Create a class library
(7) Add the System.Web reference
(8) Inherit from "UI.WebControls.Webpart"
(9) Write code to load the usercontrol in class library
(10)Build it
(11)Add the .dll into bin of virtual directory
(12)Add safe control in the web.config
(13)Go to the sharepoint site & Populate it
(14)Add that webpart into your page
(15) :)

My Masters