Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Sharepoint 2010. Resource Calendar - add new item with resource

Sharepoint 2010. Resource Calendar - add new item with resource

Scheduled Pinned Locked Moved SharePoint
csharpsharepointbusinesshelpquestion
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fxrobot
    wrote on last edited by
    #1

    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////

    A 1 Reply Last reply
    0
    • F fxrobot

      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////

      A Offline
      A Offline
      Ayan Chalki
      wrote on last edited by
      #2

      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");

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups