Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Security;
  4. using System.Net;
  5. using System.Runtime.Serialization;
  6. using System.Runtime.Serialization.Json;
  7. using Microsoft.SharePoint.Client;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. try {
  16. //Console.WriteLine("Enter the sharepoint online UserName...");
  17. String username = "username";
  18. const string password = "password";
  19. SecureString pass = new SecureString();
  20. foreach (char itemC in password.ToCharArray())
  21. {
  22. pass.AppendChar(itemC);
  23. }
  24. //pass.MakeReadOnly();
  25. Console.WriteLine();
  26. Console.WriteLine(pass);
  27. SharePointOnlineCredentials cred = new SharePointOnlineCredentials(username, pass);
  28. Console.WriteLine();
  29. Console.WriteLine("Requesting the REST...");
  30. String url = "https://serverhosr_url/sites/sitename/_vti_bin/ExcelRest.aspx/Shared%20 Documents/Template.xlsb/Model/Ranges?$format=atom";
  31.  
  32. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
  33. req.Credentials = cred;
  34. req.Headers["X-FORM_BASED_AUTH_ACCEPTED"] = "f";
  35. Console.WriteLine(req.ToString());
  36. HttpWebResponse response = (HttpWebResponse)req.GetResponse();
  37. DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(RangeResponse));
  38. RangeResponse rr = ser.ReadObject(response.GetResponseStream()) as RangeResponse;
  39. Console.WriteLine("the response is as follows.."+rr.rows[0][0].fv);
  40. Console.ReadLine();
  41. }
  42. catch (NotSupportedException) { }
  43. }
  44. }
  45. [DataContract]
  46. public class CellValue
  47. {
  48. [DataMember]
  49. public object v { get; set; }
  50. [DataMember]
  51. public object fv { get; set; }
  52. }
  53. [DataContract]
  54. public class RangeResponse
  55. {
  56. [DataMember]
  57. public String name { get; set; }
  58. [DataMember]
  59. public CellValue[][] rows { get; set; }
  60. }
  61. }
  62. this is giving error at line where the code is HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement