24 September 2009

KPI : custom Code WebPart



Here i'v developed a webpart for showing KPI indicators which are binded as desired
i have used a literal control and binded a my display structure in this literal control.

Code
//inialization
private LiteralControl Literal1;
SPSiteoCurrentSite = null;
SPWeb oweb =null;
int count;
DataTable dt =new DataTable();
string strStruct;

In CreateChildControls()
Literal1 = new LiteralControl();
Literal1.Load += new EventHandler(Literal1_Load);
Controls.Add(Literal1);
-------
on load event of Literal Control i'll be calling my Core functionlity which will be binded with this literal control.

MyFunction()
{
try {
count = 0;
//oCurrentSite = new
SPSite("http://syngdcds0138:1111");

oCurrentSite = SPContext.Current.Site;
oweb = oCurrentSite.OpenWeb();
oweb.AllowUnsafeUpdates = true;
SPList oProjectName = oweb.Lists["Tasks"];
SPQuery Query1;
DataTable Dtable;
DataView Dview;
SPListItemCollection items1;
SPUser currentUser = oweb.CurrentUser;
string UNAme = currentUser.Name;
Query1 = new SPQuery();
Dtable = new DataTable();
Dview = new DataView();
Query1.Query = "<Where><Eq><FieldRef Name='AssignedTo' /><Value Type='User'>" +
currentUser.Name + "</Value></Eq></Where>";
items1 = oProjectName.GetItems(Query1);
strStruct = "<div>" + "<table>";
foreach (SPListItem objItem in items1)
{//Pending Completed Overdue
string picture = string.Empty;
if (objItem["Status"].ToString() == "Overdue")
{ picture = @"~/_LAYOUTS/Images/ico-task-overdue.jpg";
}
else if (objItem["Status"].ToString() == "Completed")
{ picture = @"~/_LAYOUTS/Images/ico-task-Completed.jpg";
}
else
{picture = @"~/_LAYOUTS/Images/ico-task-Pending.jpg";
}
string[] CreatedBy = objItem["Created By"].ToString().Split('#');
string AssignedBY = CreatedBy[1];
string DDt = Convert.ToDateTime(objItem["DueDate"].ToString()).ToShortDateString();
strStruct += "<tr>" + "<td colspan=2 align='left'>" + "<img src='" + ResolveUrl(picture) +
"'
/>&nbsp;&nbsp;&nbsp;"
+ "<a style='text-align:right; font-size:12px;' href='" + oweb.Url +
"/Lists/" + oProjectName.Title + "/DispForm.aspx?ID=" + objItem["ID"].ToString() + "&Source=" + oweb.Url + "'>" + objItem["Title"].ToString() + "</a>" + "</td></tr>" + "<tr><td colspan=2 style= 'font-family:Arial; font-size:xx-small;'>Due Date:" + DDt + "&nbsp;&nbsp;Assigned By:"
+ AssignedBY + " </td></tr>";
}
strStruct += "<tr><td></td><td> <a href='" + oweb.Url + "/Lists/" + oProjectName.Title + "/Allitems.aspx'>More&gt;&gt</a>" + "</td></tr>" + "<tr>" +
"<td><img
src='~/_LAYOUTS/images/ico-task-Completed.jpg'> Completed "
+
"<img
src='~/_LAYOUTS/images/ico-task-Pending.jpg'> Pending "
+
"<img
src='~/_LAYOUTS/images/ico-task-overdue.jpg'> Overdue </td>"

+ "</tr>" + "</table></div>";
Literal1.Text = strStruct;
}
catch (Exception ee) { //Error}
}

Revert your comments for this article

22 September 2009

Meeting WorkSpace Webpart :- Gets All Meeting Task

This WebPart is developed get all the Task which are added in a Decision Meeting Workspace template selected. since SharePoint does not provide any out-Of-Box functionality to segregate this vital information.
hence a custom WebPart was developed by my associate.
Initially all the related reference /namespaces are added , despite of Microsoft.sharepoint;
We also be needing :
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Meetings;
//Core Code for WebPart.
public class MeetingWorkspace : System.Web.UI.WebControls.WebParts.WebPart
{

//Initilization
SPGridView m_grid;
SPWeb web1 = SPContext.Current.Web;
ObjectDataSource objDataSource = new ObjectDataSource();
//Override Methods
protected override void CreateChildControls()
{
try
{
Type type = this.GetType();
objDataSource.ID =
"mTaskDS";
objDataSource.TypeName = type.AssemblyQualifiedName;
objDataSource.SelectMethod =
"GetListItems";
objDataSource.ObjectCreating +=
new ObjectDataSourceObjectEventHandler(objDataSource_ObjectCreating);
this.Controls.Add(objDataSource);
#region SPGridView Details
m_grid =
new SPGridView();
m_grid.AutoGenerateColumns =
false;
m_grid.Columns.Clear();
HyperLinkField meetingName = new HyperLinkField();
meetingName.HeaderText =
"Meeting Name";
meetingName.DataTextField =
"MeetingName";
string[] strmeetingName = { "MeetingSiteUrl" };
meetingName.DataNavigateUrlFields = strmeetingName;
meetingName.DataNavigateUrlFormatString =
"{0}";
m_grid.Columns.Add(meetingName);

BoundField t = new BoundField();
t.DataField =
"Title";
t.HeaderText =
"Task Title";
m_grid.Columns.Add(t);
BoundField b = new BoundField();
b.DataField =
"Status";
b.HeaderText =
"Status";
b.HtmlEncode =
false;
b.SortExpression =
"Status";
m_grid.Columns.Add(b);
BoundField colStartDate = new
BoundField();
colStartDate.DataField =
"StartDate";
colStartDate.HeaderText =
"Start Date";
colStartDate.HtmlEncode =
false;
m_grid.Columns.Add(colStartDate);
BoundField colDueDate = new
BoundField();
colDueDate.DataField =
"DueDate";
colDueDate.HeaderText =
"Due Date";
colDueDate.HtmlEncode =
false;
m_grid.Columns.Add(colDueDate);
m_grid.DataSourceID =
"mTaskDS";
m_grid.AllowGrouping =
true;
m_grid.AllowGroupCollapse =
true;
m_grid.GroupField =
"MeetingName";
m_grid.GroupFieldDisplayName =
"MeetingName";
m_grid.AllowSorting =
true;
m_grid.AllowPaging =
true;
Controls.Add(m_grid);
m_grid.DataBind();
m_grid.PageSize = 3;
m_grid.PageIndexChanging +=
new GridViewPageEventHandler(m_grid_PageIndexChanging);
m_grid.PagerTemplate =
null;
#endregion

base.CreateChildControls();
}
catch(Exception ex) { //Error }
}

//Data View Method
public DataView GetListItems()
{
DataView dv = new DataView();
DataTable dt = new DataTable();
try
{
string rowFilter = "AssignedTo = '" + SPContext.Current.Web.CurrentUser.Name + "'";
foreach (SPWeb web in web1.Webs)
{
if (SPMeeting.IsMeetingWorkspaceWeb(web))
{
SPMeeting meeting = SPMeeting.GetMeetingInformation(web);
// A Meeting Workspace has a Meeting Series list with information about all meetings in the workspace.
SPList meetings = web.Lists["Meeting Series"];
// Get the meeting items that fit the criteria.
SPListItemCollection items = meetings.Items;
// Now extract useful information about each meeting.
foreach (SPListItem item in items)
{
int instanceID = (int)item["InstanceID"];
SPQuery query =new SPQuery();
query.MeetingInstanceId = instanceID;
query.Query = @"<Query> <Where><IsNotNull> <FieldRefName='ID' /> </IsNotNull></Where></Query>" ;
SPList list = web.Lists["Tasks"];
DataTable dtMItems = list.GetItems(query).GetDataTable();
if (dtMItems.Columns["MeetingName"] == null)
{
dtMItems.Columns.Add("MeetingName");
dtMItems.AcceptChanges();
}
if (dtMItems.Columns["MeetingSiteUrl"] == null)
{
dtMItems.Columns.Add("MeetingSiteUrl");
dtMItems.AcceptChanges();
}
foreach (DataRow dr in dtMItems.Rows)
{
dr["MeetingName"] = item.Title;
dr["MeetingSiteUrl"] = web.Url + "/default.aspx?InstanceID=" + instanceID.ToString();
dtMItems.AcceptChanges();
}
dt.Merge(dtMItems);
} } }
dv = new DataView(dt, rowFilter, null, DataViewRowState.CurrentRows);
}
catch (Exception ex) {//Error}

return dv;
}

//Handler
pri
vate void objDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = this;
}
private void m_grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
m_grid.PageIndex = e.NewPageIndex;
m_grid.AllowGrouping = true;
m_grid.AllowGroupCollapse = true;
m_grid.GroupField = "MeetingName";
m_grid.GroupFieldDisplayName = "MeetingName";
m_grid.DataBind();
}
catch (Exception ex) {//Error }
}
}

Addin Your Comments for the Same.

Special Thanks: Ganesh Bankar

18 September 2009

KPI in WSS

I’m adding this article to produce KPI indicators for a simple task list which will show symbolic representation for each item added.

Here I have selected a task list in which I have added a calculated field named “Indicator” and these indicators are calculated from the priority field which is categorized (high, Medium & Low).
Here is the code snippet for calculated field.
="<DIV><IMG
src='/_layouts/images/kpipeppers-"&(3-RIGHT(LEFT(Priority,2),1))&".gif'
/></DIV>"
Now added the following script in content editor webpart

<script type="text/javascript">
var theTDs = document.getElementsByTagName("TD");
var i=0;
var TDContent = " ";

while (i < theTDs.length)

{
try
{
TDContent = theTDs[i].innerText theTDs[i].textContent;
if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0))

{
theTDs[i].innerHTML = TDContent;
}

}
catch(err){}
i=i+1;
}////
ExpGroupRenderData overwrites the default SharePoint function
// This part is needed for collapsed groupings
//
function ExpGroupRenderData(htmlToRender, groupName, isLoaded)

{

var tbody=document.getElementById("tbod"+groupName+"_");
var wrapDiv=document.createElement("DIV");
wrapDiv.innerHTML="<TABLE><TBODY id=\"tbod"+ groupName+"_\"
isLoaded=\""+isLoaded+ "\">"+htmlToRender+"</TBODY></TABLE>";
var theTBODYTDs = wrapDiv.getElementsByTagName("TD"); var j=0; var TDContent = " ";
while (j < theTBODYTDs.length) {
try {
TDContent = theTBODYTDs[j].innerText theTBODYTDs[j].textContent;
if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0))

{
theTBODYTDs[j].innerHTML = TDContent;

} }
catch(err){}
}
tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
}
</script>



Special thanks: Christophe




10 September 2009

Changing Welcome Page in SharePoint.

This article is targeting on changing the default.aspx page provided by SharePoint to our Custom Page.
Since altering default home page in publishing site is easily possible, however altering the home page for TEAM site is much trick than we can imagine.
Here is a solution that can be adopted to retain a custom or user defined home to be populated as default page after login to a SharePoint portal.

>> Follow these steps for achievement.
1. Check the Content Database of the web application via.
Central Administration >> Application Management >>SharePoint Web Application Management Tab >> Conect Database

2. Cross check the content database which through which we can alter the default page.
3. Create your custom page using SharePoint designer at root level which needs to be set as default page on login.


4. Go to MS SQL management Studio.
a. Browse to database table named “WelcomeNames
b. Add the Page name (ex: Myhomepage in my case) in LeafName Column and change its rank to 1.
Bingo! Now Login to the SharePoint portal and will get this page at default home page.

Special Thanks: Abhijeet Tidke

07 September 2009

Connecting Sharepoint 2007 to your Domino LDAP server

hi,
Here is a userful link provided by Mobile Viking, that will help to connect to Domino LDAP server to fetched login users for sharepoint.
The User connection and provider steps are similar as performed during FBA with slight alteration please follow the steps provided >> Click here

Special thanks: Mobile Viking(blog)

Rate Now: