Wednesday, August 24, 2011

Convert Generic List to String


var stringBuilder = new StringBuilder();
 strings.ForEach(a=>stringBuilder.AppendFormat("{0}:",a));

Tuesday, July 19, 2011

Sharepoint Calender

Add Holiday Calendar to SharePoint:



Understanding the SharePoint calendar and how to export it to iCal format:
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=761


// Get the Events list
SPSite site = new SPSite("http://localhost");
SPWeb web = site.RootWeb;
SPList calendarList = web.Lists["Calendar"];

// Construct a query that expands recurring events
SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.Query = "";

// Look forward from the beginning of the current month
query.CalendarDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

// Returns all items (including recurrence instances) that
// would appear in the calendar view for the current month
SPListItemCollection calendarItems = calendarList.GetItems(query);

foreach (SPListItem item in calendarItems)
{
Console.WriteLine(item["Title"] + ": starts "
+ item["EventDate"].ToString() + " and ends "
+ item["EndDate"].ToString());
}

Tuesday, March 23, 2010

Generic list Example

GenericSampleClass.aspx.cs:
---------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class wfGenericSampleWithArg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GenericSampleWithArg objGenericSampleWithArg = new GenericSampleWithArg();
objGenericSampleWithArg.Push(9);
int Resultint = objGenericSampleWithArg.pop();

GenericSampleWithArg objGenericSampleWithArgstring = new GenericSampleWithArg();
objGenericSampleWithArgstring.Push("sri");
string Resultstring = objGenericSampleWithArgstring.pop();

drpCollection.DataSource = GetUserWithArg();
drpCollection.DataBind();

drpCollectionwithCalss.DataTextField = "userName";
drpCollectionwithCalss.DataSource = GetUserswithClass();
drpCollectionwithCalss.DataBind();
}

private object GetUserWithArg()
{
ListItemCollection addtCollection = new ListItemCollection();
for (int i = 0; i <= 5; i++)
{
addtCollection.Add(new ListItem("sri" + i.ToString()));
}
this.lstCollection = addtCollection;
return this.lstCollection;
}

private List GetUserswithClass()
{
List objListGenericSampleWithArg = new List();
for (int j = 0; j <= 9; j++)
{
objListGenericSampleWithArg.Add(new genericSamplewithClass(j, "sri" + j.ToString()));
}
this.users = objListGenericSampleWithArg;
return this.users;
}

private ListItemCollection _lstCollection;
public ListItemCollection lstCollection
{
get
{
return _lstCollection;
}
set
{
_lstCollection = value;
}
}

private List _users;
public List users
{
get
{
return _users;
}
set
{
_users = value;
}
}
}

genericSamplewithClass.cs:
--------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for genericSamplewithClass
///

public class genericSamplewithClass
{
public genericSamplewithClass()
{
//
// TODO: Add constructor logic here
//
}

public genericSamplewithClass(int userId, string userName)
{
this.userId = userId;
this.userName = userName;
}

public genericSamplewithClass(int userId, string userName, string address)
{
this.userId = userId;
this.userName = userName;
this.address = address;
}

private string _userName;
private int _userId;
private string _address;
public int userId
{
get
{
return _userId;
}
set
{
_userId = value;
}
}
public string userName
{
get
{
return _userName;
}
set
{
_userName = value;
}
}

public string address
{
get
{
return _address;
}
set
{
_address = value;
}
}
}

Wednesday, March 10, 2010

Count work days between two dates in SQL

declare @StartDate datetime,@EndDate datetime
select @StartDate='3/2/2010', @EndDate='3/7/2010'
DECLARE @TotalDays INT,@WorkDays INT
DECLARE @ReducedDayswithEndDate INT
DECLARE @WeekPart INT
DECLARE @DatePart INT
SET @TotalDays= DATEDIFF(day, @StartDate, @EndDate) +1
SELECT @ReducedDayswithEndDate = CASE DATENAME(weekday, @EndDate)
WHEN 'Saturday' THEN 1
WHEN 'Sunday' THEN 2
ELSE 0 END
SET @TotalDays=@TotalDays-@ReducedDayswithEndDate
SET @WeekPart=@TotalDays/7;
SET @DatePart=@TotalDays%7;
SET @WorkDays=(@WeekPart*5)+@DatePart
SELECT @WorkDays