Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. static void Main(string[] args)
  2. { try {
  3. Microsoft.SharePoint.Client.ClientContext clientContextproj =
  4. new Microsoft.SharePoint.Client.ClientContext("");
  5. Web siteproj = clientContextproj.Web;
  6. // clientContextproj.AuthenticationMode =
  7. //ClientAuthenticationMode.Default;
  8. // clientContextproj.Credentials = new
  9. //System.Net.NetworkCredential("username", "password",
  10. //"domain");
  11. CamlQuery query1 = new CamlQuery();
  12. query1.ViewXml = "<View><Query><FieldRef Name='Country'/>
  13. <Value Type='Text'></Value></Query></View>";
  14.  
  15. List resourceMaster = siteproj.Lists.GetByTitle("Test1");
  16. Microsoft.SharePoint.Client.ListItemCollection items =
  17. resourceMaster.GetItems(query1);
  18. clientContextproj.Load(items);
  19. clientContextproj.ExecuteQuery();
  20. Excel.Application ap = new Excel.Application();
  21. Excel.Workbook wb =
  22. ap.Workbooks.Open("C:\Users\sa06\Desktop\Report.xlsx");
  23. Excel.Worksheet ws = wb.ActiveSheet;
  24. bool flag = true;
  25. int counter = 2;
  26. while (flag)
  27. {
  28. string columnHeader = "A" + counter.ToString();
  29. Microsoft.Office.Interop.Excel.Range row =
  30. ws.get_Range(columnHeader);
  31. row.Value2 = row.Text.ToString().Trim();
  32. if (row.Value2 != null)
  33. {
  34. if (items.Count != 0)
  35. {
  36. foreach (ListItem listItem in items)
  37. {
  38. Console.WriteLine(listItem["Country"]);
  39. var currentResourceId = listItem["Country"];
  40. if (currentResourceId != null &&
  41. currentResourceId.Equals(row.Value2))
  42. {
  43. Microsoft.Office.Interop.Excel.Range Exprow =
  44. ws.get_Range("B" + counter.ToString());
  45. string ValueTotal =
  46. Convert.ToString(Exprow.Value2);
  47. listItem["Region"] = ValueTotal;
  48. listItem.Update();
  49. clientContextproj.ExecuteQuery();
  50. break;
  51. } }
  52. } }
  53. else
  54. { flag = false; }
  55. } }
  56.  
  57. catch (Exception ex)
  58. {
  59. throw ex;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement