Archive for March, 2008
great collection of sharepoint resources, tools, tips n tricks
Posted by sNjY on March 25, 2008
Posted in Technology | Leave a Comment »
Single web part to display tasks assigned to current user and current user’s groups
Posted by sNjY on March 21, 2008
The kind of requirement is understood from the title itself, but moss 2007, as such, donot have any out of the box webparts to achieve this.
We do have ‘by my groups’ view to display tasks assigned to current user’s groups.
and ‘my taks’ view to display tasks assinged to current user.
After googling for some time to see if i have any webparts for free or if somebody has already done it and posted his ideas, i ended up writing one on my own.
Here is the source code for the base version.
using System;
using System.Collections.Generic;
namespace sa.WebParts.WebPartToDisplayGroupTasks{ [DefaultProperty("Text"),ToolboxData("<{0}:SPWebPart runat=server></{0}:SPWebPart>"),
XmlRoot(Namespace = "sa.WebParts.WebPartToDisplayGroupTasks")]public class SPWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{private const EnumStatus _defaultStatus = EnumStatus.NotCompleted;private EnumStatus _enumStatus = _defaultStatus;
GridView GridView1 = new GridView();public enum EnumStatus
{NotStarted = 0,
InProgress = 1,
Completed=2,
NotCompleted=3
}
[Browsable(true),Category("Configuration"),
DefaultValue(EnumStatus.NotCompleted),WebPartStorage(Storage.Personal),
FriendlyName("Status"),Description("Select Status.")]
public EnumStatus Status{get { return _enumStatus; }set
{_enumStatus = value;}}
public SPWebPart(){
this.Title = “Webpart to display Group Tasks”;} protected override void CreateChildControls(){Microsoft.SharePoint.SPList listSiteSetup = SPContext.Current.Web.Lists["Tasks"];Microsoft.SharePoint.SPQuery query = new Microsoft.SharePoint.SPQuery();Microsoft.SharePoint.
SPListItemCollection items = listSiteSetup.Items;DataTable dtTasks = items.GetDataTable();
DataColumn dtLink = new DataColumn(“link”);dtTasks.Columns.Add(dtLink);//Columns to Display
string[] link = new string[1];link[0] = “link”;
HyperLinkField hlfTitle = new HyperLinkField();hlfTitle.DataTextField = “Title”;hlfTitle.HeaderText =
“Title”;hlfTitle.DataNavigateUrlFields = link;BoundField bfStatus = new BoundField();bfStatus.HeaderText = “Status”;bfStatus.DataField =
“Status”;BoundField bfStartDate = new BoundField();bfStartDate.DataField =
“StartDate”;bfStartDate.HeaderText = “Start Date”;
BoundField bfDueDate = new BoundField();bfDueDate.HeaderText = “Due Date”;bfDueDate.DataField =
“DueDate”;BoundField bfAssignedTo = new BoundField();bfAssignedTo.DataField =
“AssignedTo”;bfAssignedTo.HeaderText = “Assigned To”;GridView1.Columns.Add(hlfTitle);GridView1.Columns.Add(bfStatus);
GridView1.Columns.Add(bfStartDate);
GridView1.Columns.Add(bfDueDate);
GridView1.Columns.Add(bfAssignedTo);
GridView1.AutoGenerateColumns = false;foreach (DataRow dr in dtTasks.Rows){ dr["link"] = SPContext.Current.Web.Url + “/Lists/Tasks/DispForm.aspx?ID=” + Convert.ToString(dr["ID"]) + “&Source=” + SPContext.Current.Web.Url;}SPUser user = SPContext.Current.Web.CurrentUser;
string rowFilter = “AssignedTo = ‘” + user.Name + “‘”;SPGroupCollection userGroupsColle = user.Groups;
foreach (SPGroup grp in userGroupsColle){ rowFilter = rowFilter + ” OR AssignedTo = ‘” + grp.Name + “‘”;}string statusFilter = null;DataView dv = new DataView(dtTasks, rowFilter, null, DataViewRowState.CurrentRows);
switch (Status){case EnumStatus.NotCompleted:{statusFilter =
“Status=’In Progress’ OR Status=’Not Started’”;break;}case EnumStatus.Completed:statusFilter =
“Status=’Completed’”;break;
case EnumStatus.InProgress:statusFilter = “Status=’In Progress’”;
break;case EnumStatus.NotStarted:statusFilter =
“Status=’Not Started’”;break;
default:break;}dv = new DataView(dv.ToTable(), statusFilter, null, DataViewRowState.CurrentRows);
Label Label1 = new Label();Label1.Text = “There are no tasks to be completed by you or your group”;GridView1.DataSource = dv.ToTable();GridView1.DataBind();
if (dv.ToTable().Rows.Count == 0){ Label1.Visible = true;}else
Label1.Visible = false; this.Controls.Add(GridView1);this.Controls.Add(Label1);
base.CreateChildControls();}}
}
The approach is very obvious from the code above: yet again here it is in short:
1. Fetch the tasks from the tasks list.
2.Get the datatable version of tasks.
3.Decide on the columns to be shown and get the data from the datatable.
4.Apply necessary filters to the data ( Assigned to equal to Current user or current users groups.
5.Render the grid view control after binding the datasource.
6.THERE YOU Go!
7.There is Status filter also, which is a cusmizable property of the webpart and can be set to Completed, Not completed, In progress or Not started.
Posted in Technology | Tagged: current user tasks and current users group tasks, moss 2007, sharepoint, tasks webpart | 26 Comments »
Search Complete
Posted by sNjY on March 5, 2008
Following is a link to a MSDN article. The article is an excerpt from a sharepoint book called Inside MOSS.
Really a very good article. Covers everything of MOSS search.
http://msdn2.microsoft.com/en-us/library/bb608304.aspx
Go Read Go Search
Posted in Technology | Tagged: Modify xslt for search, MOSS Search | Leave a Comment »
When Sharepoint list lookup field is rendered as INPUT instead of SELECT..HOW to DISABLE?
Posted by sNjY on March 3, 2008
When the number of items in a lookup field exceeds 20, then the control is rendered as an INPUT control by Sharpoint.
Next, lets say you want to disable the lookup field through javascript.
This is straightforward.Isn’t it?
Find the control and set disable=true.
No.
The lookup control looks disabled but if you click over it, a dropdown shows up. Don’t get surprised. Sharepoint aactually inserted an Image button next to the INPUT control, which you have not disabled yet.
The image button on click calls SHOWDROPDOWN function to render the items and show.
So this is how you disable both the controls straightforward,
Just call this function with the title of the lookup field:
like
Disable(“Document Types”);
function Disable(Controltitle)
{
for(var i = 0; i < document.all.length; i++)
{
var firstOne = document.all[i];
if(firstOne.title == Controltitle)
{
firstOne.disabled = true; //INPUT control disabled
if(i < document.all.length - 1)
{
//Image button lies next to the INPUT control and refers to the INPUT control
var secondOne = document.all[i + 1];
if(secondOne.outerHTML.indexOf(firstOne.id) > 0)
{ //This evalautes true since Image button has the lookup field id to call showdropdown function
secondOne.disabled = true;
}
}
break;
}
}
}
Posted in Technology | Tagged: disable INPUT control sharepoint, lookup field sharepoint not disabled, sharepoint lookup field disable. | 3 Comments »
Real world Sharepoint 2007
Posted by sNjY on March 1, 2008
The title of this post is also the title of a sharepoint book by 16 moss and wss mvps.
I recently flicked through the book.
Here are the blogs addresses and sites of some of these MVPS.
1. http://www.thorprojects.com/blog
2. http://www.andrewconnell.com/blog
3. http://www.sharepointblogs.com/ldusolier
9. http://www.graphicalwonder.com
12. www.heathersolomon.com/blog
Posted in Technology | Tagged: Sharepoint MVP blogs sites, sharepoint MVPS | 1 Comment »
Execute your timer job immediately with STSADM
Posted by sNjY on March 1, 2008
By using the STSADM operation execadmsvcjobs, we can force the timer job to execute immediately.This helps us when we donot want to wait until the scheduled time is reached.
Posted in Technology | Tagged: sharepoint timer job, stsadm execadmsvcjobs | 3 Comments »


