Skip to main content

Posts

Showing posts from May, 2009

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() == "S

Read INI Files

here is class that make ur life easier when reading an INI file :D when u add this class, u can use it right away..something like this will work first import some namespace C# using Org.Mentalis.Files; IniReader oINI = new IniReader(PATH_TO_INI_FORMAT_HERE); Console.WriteLine(oINI.ReadString("DOMAIN", "Name")); Console.WriteLine(oINI.ReadString("DOMAIN", "SMTP")); the INI file format will be something like attached, as you see it's name are .txt not .ini, it doesn't matter as long the format is an INI file where u have Section (ie: DOMAIN) and Key (ie: "Name" and "SMTP") until then PS: i'm using console application

Write to Log Files

if you want to write some success or failed event to log file, then this is the code first u need to using this namespace C# using System.IO; FileStream file; if (File.Exists("FILE_NAME_HERE")) { file = new FileStream( "FILE_NAME_HERE", FileMode.Append, FileAccess.Write); } else { file = new FileStream( "FILE_NAME_HERE", FileMode.Create, FileAccess.Write); } // Create a new stream to write to the file StreamWriter sw = new StreamWriter(file); // Write a string to the file sw.WriteLine("module: some module have an error at " + System.DateTime.Now.ToString()); // Close StreamWriter sw.Close(); // Close file file.Close();

Get User in Active Directory

here i want to get User's Superior in AD (which is manager in AD hierarchy, see attached) PS: you must set it at Organization Tab in User Properties in Active Directory User and Computers C# private static void GetManager(string _Username, string _Domain) { DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, _Domain); DomainControllerCollection dcc = DomainController.FindAll(context); foreach (DomainController dc in dcc) { DirectorySearcher ds; using (dc) using (ds = dc.GetDirectorySearcher()) { ds.Filter = String.Format("(sAMAccountName={0})", _Username); ds.PropertiesToLoad.Add("manager"); ds.PropertiesToLoad.Add("mail"); ds.SizeLimit = 1; SearchResul

Emailing User in .NET

i use this code, i forgot where i got it so credit goes to him/her C# MailMessage mailMessage = new MailMessage(_FromAddress, _ToAddress); //mailMessage.CC.Add(_CCAddress); mailMessage.Subject = Program.my1stSubjectText; mailMessage.Body = Program.my1stReminderText; mailMessage.IsBodyHtml = true; mailMessage.Subject = "tes Subject"; mailMessage.Body = "HTML can be use here really :D " SmtpClient mailSender = new SmtpClient("SMTP_SERVER_HERE"); try { mailSender.Send(mailMessage); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } until then

almost a year again since my last post :D

many has change now..i'm try to post my knowledge and make it routine :D now i'm working at new employer since my plan to work by myself is not a great idea (according to my colleague Robby, thx for that) in here, we are M$ partner with product like Sharepoint, Project Server, Custom Development and it involved alot of technology like Workflow, WPF, SQL Reporting Service, Silverlight, Infopath, etc and also .NET of course. So i'm learning alot eventhough not mastering any product yet.. at first i'm working for MOSS and Infopath, a lot confusing day back then since the node documentation about it is nearly nothing (especially InfoPath) and i'm learning it from Google. ok, i thinks that's enough for now..feel free to contact me until then