TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sreenu kolusu
NA
38
181k
Get Leave Days with out holidays & Week Days Using Sharepoint 2010 Event Receivers
Aug 9 2012 2:24 PM
public override void ItemAdding(SPItemEventProperties properties)
{
if (properties.ListTitle!="Contractor Attendance")
{
properties.Cancel = true;
}
else
{
DateTime Fdate = Convert.ToDateTime(properties.AfterProperties["From_x0020_Date"]).AddDays(1);
DateTime Tdate = Convert.ToDateTime(properties.AfterProperties["To_x0020_Date"]).AddDays(1);
TimeSpan ts = Tdate.Subtract(Fdate);
int days = Convert.ToInt32(ts.Days) + 1;
for (var day = Fdate.Date; day.Date <= Tdate.Date; day = day.AddDays(1))
{
if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday)
{
days--;
}
}
SPWeb myweb = properties.OpenWeb();
myweb.AllowUnsafeUpdates = true;
SPList mylist = myweb.Lists["Holidays List"];
SPListItemCollection lic = mylist.Items;
foreach (SPListItem item in mylist.Items)
{
DateTime Hdate = Convert.ToDateTime(item["Date"]);
for (var day = Fdate.Date; day.Date <= Tdate.Date; day = day.AddDays(1))
{
if (day == Hdate)
{
days--;
}
}
}
properties.AfterProperties["Days"] = Convert.ToInt32(days);
}
}
Reply
Answers (
0
)
Backup & Restore SharepointSite
"The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator”.