Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- { try {
- Microsoft.SharePoint.Client.ClientContext clientContextproj =
- new Microsoft.SharePoint.Client.ClientContext("");
- Web siteproj = clientContextproj.Web;
- // clientContextproj.AuthenticationMode =
- //ClientAuthenticationMode.Default;
- // clientContextproj.Credentials = new
- //System.Net.NetworkCredential("username", "password",
- //"domain");
- CamlQuery query1 = new CamlQuery();
- query1.ViewXml = "<View><Query><FieldRef Name='Country'/>
- <Value Type='Text'></Value></Query></View>";
- List resourceMaster = siteproj.Lists.GetByTitle("Test1");
- Microsoft.SharePoint.Client.ListItemCollection items =
- resourceMaster.GetItems(query1);
- clientContextproj.Load(items);
- clientContextproj.ExecuteQuery();
- Excel.Application ap = new Excel.Application();
- Excel.Workbook wb =
- ap.Workbooks.Open("C:\Users\sa06\Desktop\Report.xlsx");
- Excel.Worksheet ws = wb.ActiveSheet;
- bool flag = true;
- int counter = 2;
- while (flag)
- {
- string columnHeader = "A" + counter.ToString();
- Microsoft.Office.Interop.Excel.Range row =
- ws.get_Range(columnHeader);
- row.Value2 = row.Text.ToString().Trim();
- if (row.Value2 != null)
- {
- if (items.Count != 0)
- {
- foreach (ListItem listItem in items)
- {
- Console.WriteLine(listItem["Country"]);
- var currentResourceId = listItem["Country"];
- if (currentResourceId != null &&
- currentResourceId.Equals(row.Value2))
- {
- Microsoft.Office.Interop.Excel.Range Exprow =
- ws.get_Range("B" + counter.ToString());
- string ValueTotal =
- Convert.ToString(Exprow.Value2);
- listItem["Region"] = ValueTotal;
- listItem.Update();
- clientContextproj.ExecuteQuery();
- break;
- } }
- } }
- else
- { flag = false; }
- } }
- catch (Exception ex)
- {
- throw ex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement