Hi All,
Below is code written to access Calendar data.. Highlighted code gives an
error
#region Calendar Events
protected void btnShowGC_Click(object sender, EventArgs e)
{
GetCalendarEvents();
}
private DataTable FillDataTable()
{
try
{
DataTable dtContacts = new DataTable();
DataColumn dtContactsCol = new DataColumn();
dtContactsCol.ColumnName = "EventTitle";
dtContactsCol.DataType =
System.Type.GetType("System.String");
dtContacts.Columns.Add(dtContactsCol);
dtContactsCol = new DataColumn();
dtContactsCol.ColumnName = "Author";
dtContactsCol.DataType =
System.Type.GetType("System.String");
dtContacts.Columns.Add(dtContactsCol);
dtContactsCol = new DataColumn();
dtContactsCol.ColumnName = "Location";
dtContactsCol.DataType =
System.Type.GetType("System.String");
dtContacts.Columns.Add(dtContactsCol);
dtContactsCol = new DataColumn();
dtContactsCol.ColumnName = "StartTime";
dtContactsCol.DataType =
System.Type.GetType("System.DateTime");
dtContacts.Columns.Add(dtContactsCol);
dtContactsCol = new DataColumn();
dtContactsCol.ColumnName = "EndTime";
dtContactsCol.DataType =
System.Type.GetType("System.DateTime");
dtContacts.Columns.Add(dtContactsCol);
return dtContacts;
}
catch
{
return null;
}
}
protected void GetCalendarEvents()
{
try
{
CalendarService oSrv = new
CalendarService("GoogleAPIs_Cal_V1");
EventQuery oQuery = new EventQuery();
oQuery.Uri = new Uri("*URL of PUblic CAlendar*");
if (strUserName != null && strUserName.Length > 0)
{
oSrv.setUserCredentials(strUserName, strPwd);
}
oQuery.StartTime = DateTime.Now.AddHours(-11);
oQuery.EndDate = DateTime.Now.AddDays(1);
EventFeed calFeed = oSrv.Query(oQuery) as EventFeed;
ArrayList dates = new ArrayList(50);
DataTable dtEvents = FillDataTable();
while (calFeed != null && calFeed.Entries.Count > 0)
{
// look for the one with dinner time...
foreach (Google.GData.Calendar.EventEntry entry in
calFeed.Entries)
{
DataRow dtRow = dtEvents.NewRow();
dtRow["EventTitle"] = entry.Title.Text;
string strLoc = string.Empty;
string strAuth = string.Empty;
foreach (Where loc in entry.Locations)
{
strLoc += loc.ValueString + ";";
}
dtRow["Location"] = strLoc;
foreach (AtomPerson loc in entry.Authors)
{
strAuth += loc.Name + ";";
}
dtRow["Author"] = strAuth;
this.entryList.Add(entry);
if (entry.Times.Count > 0)
{
foreach (When w in entry.Times)
{
dtRow["StartTime"] = w.StartTime;
dtRow["EndTime"] = w.EndTime;
dates.Add(w.StartTime);
}
}
dtEvents.Rows.Add(dtRow);
}
// just query the same query again.
if (calFeed.NextChunk != null)
{
oQuery.Uri = new Uri(calFeed.NextChunk);
calFeed = oSrv.Query(oQuery) as EventFeed;
}
else
calFeed = null;
}
grdEvents.DataSource = dtEvents;
grdEvents.DataBind();
DateTime[] aDates = new DateTime[dates.Count];
int i = 0;
foreach (DateTime d in dates)
{
aDates[i++] = d;
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
#endregion
Please help me out.
Thanks,
T.
--
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html