Hi Friends,
In my scenario we are working on conference room management system through resource calendar our implementation is done and system ready to move on production.
But In our case the there are some booking from todays date to 6 months ahead and those booking in simple Excel format.
Now we are in process to move Excel booking data in SharePoint Resource calendarbut facing some issues due to below Reasons,
1. Resource calendar list contain some LookUp column like Resources,Building names.... etc.
2. Using .net client object model we are able to move only non lookup column from excel.
our code sample as below,
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using Microsoft.SharePoint.Client; using System.Reflection; using System.Runtime.InteropServices; using Microsoft.Office.Interop.Excel; using Microsoft.Office.Tools.Excel; namespace SPCsom { public partial class sample1form : System.Windows.Forms.Form { ClientContext clientContext; public sample1form() { InitializeComponent(); clientContext = new ClientContext("http://stkpsptestw01:8577/sites/eams/EAMS/Testsite"); } private void button1_Click(object sender, EventArgs e) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:\Copy of CRBS.xlsx", Type.Missing, false, Type.Missing, false, false, true, Type.Missing, "\t", true, true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, Type.Missing); Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; for (int i = 2; i < rowCount; i++) // Row index starts from 2, as the first row is Title { Dictionary<int, string> column = GetColumnMapping(); List oList = clientContext.Web.Lists.GetByTitle("Confroom Booking"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); Microsoft.SharePoint.Client.ListItem oListItem = oList.AddItem(itemCreateInfo); for (int j = 0; j < colCount+1; j++) { if (column.ContainsKey(j)) if (column[j].ToString().Equals("Attendees", StringComparison.OrdinalIgnoreCase)) oListItem[column[j]] = FieldUserValue.FromUser(xlWorksheet.Cells[i, j].Value); else if (column[j].ToString().Equals("Author", StringComparison.OrdinalIgnoreCase)) oListItem[column[j]] = FieldUserValue.FromUser(xlWorksheet.Cells[i, j].Value); else oListItem[column[j]] = xlWorksheet.Cells[i, j].Value; oListItem.Update(); } clientContext.ExecuteQuery(); } } private Dictionary<int, string> GetColumnMapping() { Dictionary<int, string> map = new Dictionary<int, string>(); map.Add(1, "Title"); // First parameter is the column Index in Excel Sheet and Second Param is SharePoint List's Column Name (Display Name ) map.Add(2, "Category"); map.Add(3, "Room_x0020_For"); map.Add(4, "Lunch"); map.Add(5, "Attendees"); map.Add(6, "EventDate"); map.Add(7, "EndDate"); map.Add(8, "Sitting_Capacity"); map.Add(9, "Projector"); map.Add(10, "BuildingName"); map.Add(11, "Facilities"); map.Add(12, "Description"); map.Add(13, "Author"); return map; } } }
our excel is as follow
So please suggest us Solution approach so that we can able to add Resourse calendar item with lookup field.
Thanks,
Digambar k.