Sharepoint 2010. Resource Calendar - add new item with resource
-
Hi, I'm having some difficult adding a resource to when adding a new item using C#. I opened a new Calendar with Resource Reservation option enabled. I also added "Room1" to the resources list in the site. part of my code :
using (SPSite site = new SPSite("http://sps/mysite")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists\["Rooms"\]; if (list != null) { SPListItem item = list.Items.Add(); item\["Title"\] = "New Resource sched.."; item\["Description"\] = "check resource sched.."; item\["Resources"\] = "??"; //<- what to put here??? item\["Start Time"\] = DateTime.Now.AddDays(2); item\["End Time"\] = DateTime.Now.AddDays(3); item\["Category"\] = "Business"; item\["fAllDayEvent"\]= false; item.Update(); } else { System.Console.WriteLine("List does not exists"); System.Console.ReadLine(); } } }
what do I need to write in : item["Resources"] ? writing "=Room1" doesn't work and I probably need to link the "Room1" item in the resources list. appreciate your help////
-
Hi, I'm having some difficult adding a resource to when adding a new item using C#. I opened a new Calendar with Resource Reservation option enabled. I also added "Room1" to the resources list in the site. part of my code :
using (SPSite site = new SPSite("http://sps/mysite")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists\["Rooms"\]; if (list != null) { SPListItem item = list.Items.Add(); item\["Title"\] = "New Resource sched.."; item\["Description"\] = "check resource sched.."; item\["Resources"\] = "??"; //<- what to put here??? item\["Start Time"\] = DateTime.Now.AddDays(2); item\["End Time"\] = DateTime.Now.AddDays(3); item\["Category"\] = "Business"; item\["fAllDayEvent"\]= false; item.Update(); } else { System.Console.WriteLine("List does not exists"); System.Console.ReadLine(); } } }
what do I need to write in : item["Resources"] ? writing "=Room1" doesn't work and I probably need to link the "Room1" item in the resources list. appreciate your help////
you can try like this SPList ResourcesList = web.Lists["Resources"]; SPQuery query= '..write the query to get the Room1 resources item..'; SPListItem room= ResourcesList.GetItems(query)[0]; .... item[Resources]= new SPFieldLookupValue(Convert.ToInt32(room["ID"]), "Room1");