Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Net;
  7. using System.Web.UI.WebControls;
  8. using Google.GData.Calendar;
  9. using Google.GData.Extensions;
  10. using Google.GData.AccessControl;
  11. using Google.GData.Client;
  12. public partial class Calender : System.Web.UI.Page
  13. {
  14. public static Uri oCalendarUri;
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. //eventEntry();
  18. try{
  19. string sGoogleUserName = "xxxxxxxxx@gmail.com";
  20. string sGooglePassword = "xxxxxxxx";
  21. Uri oCalendarUri = new Uri("http://www.google.com/calendar/feeds/" + sGoogleUserName + "/private/full");
  22.  
  23. //Initialize Calendar Service
  24. CalendarService oCalendarService = new CalendarService("API Project");
  25. oCalendarService.setUserCredentials(sGoogleUserName, sGooglePassword);
  26.  
  27. //Use Proxy
  28. //GDataRequestFactory oRequestFactory = (GDataRequestFactory)oCalendarService.RequestFactory;
  29. //WebProxy oWebProxy = new WebProxy(WebRequest.DefaultWebProxy.GetProxy(oCalendarUri));
  30. //oWebProxy.Credentials = CredentialCache.DefaultCredentials;
  31. //oWebProxy.UseDefaultCredentials = true;
  32. //oRequestFactory.Proxy = oWebProxy;
  33.  
  34.  
  35. //Set Event Entry
  36. Google.GData.Calendar.EventEntry oEventEntry = new Google.GData.Calendar.EventEntry();
  37. oEventEntry.Title.Text = "Test Calendar Entry From .Net";
  38. oEventEntry.Content.Content = "Hurrah!!! I posted my first Google calendar event through .Net";
  39.  
  40. //Set Event Location
  41. Where oEventLocation = new Where();
  42. oEventLocation.ValueString = "New Zealand";
  43. oEventEntry.Locations.Add(oEventLocation);
  44.  
  45. //Set Event Time
  46. When oEventTime = new When(new DateTime(2011, 5, 31, 9, 0, 0), new DateTime(2011, 5, 31, 9, 0, 0).AddHours(1));
  47. oEventEntry.Times.Add(oEventTime);
  48.  
  49. //Set Additional Properties
  50. ExtendedProperty oExtendedProperty = new ExtendedProperty();
  51. oExtendedProperty.Name = "SynchronizationID";
  52. oExtendedProperty.Value = Guid.NewGuid().ToString();
  53. oEventEntry.ExtensionElements.Add(oExtendedProperty);
  54.  
  55. // CalendarService oCalendarService = GAuthenticate();
  56.  
  57. //Prevents This Error
  58. //{"The remote server returned an error: (417) Expectation failed."}
  59. System.Net.ServicePointManager.Expect100Continue = false;
  60.  
  61. //Save Event
  62. oCalendarService.Insert(oCalendarUri, oEventEntry);
  63. }
  64. catch (Exception ex)
  65. {
  66. Response.Write(ex.Message);
  67. }
  68. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement