Skip to main content

Mark Saturday and Sunday as Holiday in Sharepoint List


at this example i'm using INI file again (read up my previous post to see it) to update Sharpeoint List for 1 year calendar

C#

IniReader oINI = new IniReader(PATH_TO_INI_FORMAT_HERE);
myPWAUrl = oINI.ReadString("DOMAIN", "PWA");
myCalendarList = oINI.ReadString("DOMAIN", "Calendar");

static void UpdateCalendar()
{
SPSite oSite = new SPSite(myPWAUrl);
SPWeb oWeb = oSite.OpenWeb();

//list is already exists then delete it
oWeb.Lists[myCalendarList].Delete();
oWeb.Update();

oWeb.Lists.Add(myCalendarList, "Enterprise Holidays", SPListTemplateType.Events);
oWeb.Update();

SPList oList = oWeb.Lists[myCalendarList];
oList.OnQuickLaunch = true;
oList.Update();

DateTime StartDate = new DateTime(System.DateTime.Today.Year, 1, 1);
DateTime CurrentDate;

for (int i = 1; i <= 365; i++) { if (i > 1)
{
CurrentDate = StartDate.AddDays(i - 1);
if (CurrentDate.DayOfWeek.ToString() == "Saturday"
CurrentDate.DayOfWeek.ToString() == "Sunday")
{
SPListItem oItem;
oItem = oList.Items.Add();

oItem["Title"] = "Holiday";

oItem["Start Time"] = CurrentDate.ToString("dd MMM yyyy 00:00");
oItem["End Time"] = CurrentDate.ToString("dd MMM yyyy 23:59");
oItem["All Day Event"] = "True";

oItem.Update();
}

//Console.WriteLine("{0} - {1}",
// StartDate.AddDays(i - 1).ToString("dd MMM yyyy 00:00"),
// StartDate.AddDays(i - 1).ToString("dd MMM yyyy 23:59"));
}
else
{
CurrentDate = StartDate;

if (CurrentDate.DayOfWeek.ToString() == "Saturday"
CurrentDate.DayOfWeek.ToString() == "Sunday")
{
SPListItem oItem;
oItem = oList.Items.Add();

oItem["Title"] = "Holiday";

oItem["Start Time"] = CurrentDate.ToString("dd MMM yyyy 00:00");
oItem["End Time"] = CurrentDate.ToString("dd MMM yyyy 23:59");
oItem["All Day Event"] = "True";

oItem.Update();
}

//Console.WriteLine("{0} - {1}",
// StartDate.ToString("dd MMM yyyy 00:00"),
// StartDate.ToString("dd MMM yyyy 23:59"));
}

if (CurrentDate.Year != System.DateTime.Today.Year) break;

}
}


the result will be like in attached

until then :D

PS: u must use Calendar type as the new list

Comments

Popular posts from this blog

Crystal Report 2010 - Failed to load database information

"Failed to load database information" error when i try deploy my program with CR 2010 using TTX file as report definition this is because there is missing .dll, call "CRDB_FIELDDEF.DLL"..u need to manually copy the file to "C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86" folder then the report is loading again it said that TTX is old tech but i'm still using it because i don't need to connect the report to any DB, but until i found new one to replace :D check this link to read it [EDIT 25 Jan 2011] i think i'll using ADO.NET Dataset next time :D until then

Session timeout problem in IIS

Hi, Long time no post, i will try to post again since i came out searching a typical solution over and over again :D Now i'm gonna post about session. Since i got this from other link so here it is So I started looking into the IIS settings and came to know that i missed two things to change : Application pool’s Idle Time-out (minutes) Session state  – State server’s Time-out (seconds) Once I have changed above settings than after Session timeout worked. So after that I have made one checklist that can help us to validate Session timeout settings, here i am sharing it with you as well so that you will also get some benefits from it : Application Pool  – Advanced Settings Menu – Process Model – Idle Time-out (minutes) Sites –  Session State  – Cookie Settings – Time-out (minutes) If you are using  State Server  or  SQL Server  to manage your session (instead of InProcess), Here is the steps to follow :    ...

Could not load file or assembly error in VS 2010 and CR

when u received this kind of error "Could not load file or assembly 'file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified." try to add this to your .config file (usually app.config) PS: don't forget to remove extra space after " see u