Getting Outlook Calendar Items to Grid view in ASP.NET












0















I am trying to get outlook calendar items using Microsoft.Office.Interop.Outlook to a gridview table in ASP.NET. I have no problem getting the data to a listbox but I need to have it in a gridview table format.



I'm not getting any errors when running the code, it's just not showing any data.



        public void GetAllCalendarItems()
{
DataTable calendardata = new DataTable();
calendardata.Columns.Add("Subject", typeof(string));
calendardata.Columns.Add("StartDate", typeof(DateTime));

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
Recipient outlookAccount = oApp.Session.CreateRecipient("outofoffice");
CalendarFolder = mapiNamespace.GetSharedDefaultFolder(outlookAccount, OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{

DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;

foreach (DataRow dr in calendardata.Rows)
{
tblCalendar.DataSource = calendardata;
tblCalendar.DataBind();
}
}
}


Here is the asp.net code:



        <asp:GridView ID="tblCalendar" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped" Visible="true">
<RowStyle CssClass="myrow" />
<AlternatingRowStyle CssClass="myrow" />
<Columns>
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" />

</Columns>
</asp:GridView>









share|improve this question

























  • It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

    – jdweng
    Jan 2 at 17:09











  • That still did not work.

    – Shane
    Jan 2 at 17:19











  • Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

    – jdweng
    Jan 2 at 17:26











  • No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

    – Shane
    Jan 2 at 17:47






  • 1





    You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

    – jdweng
    Jan 2 at 17:58
















0















I am trying to get outlook calendar items using Microsoft.Office.Interop.Outlook to a gridview table in ASP.NET. I have no problem getting the data to a listbox but I need to have it in a gridview table format.



I'm not getting any errors when running the code, it's just not showing any data.



        public void GetAllCalendarItems()
{
DataTable calendardata = new DataTable();
calendardata.Columns.Add("Subject", typeof(string));
calendardata.Columns.Add("StartDate", typeof(DateTime));

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
Recipient outlookAccount = oApp.Session.CreateRecipient("outofoffice");
CalendarFolder = mapiNamespace.GetSharedDefaultFolder(outlookAccount, OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{

DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;

foreach (DataRow dr in calendardata.Rows)
{
tblCalendar.DataSource = calendardata;
tblCalendar.DataBind();
}
}
}


Here is the asp.net code:



        <asp:GridView ID="tblCalendar" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped" Visible="true">
<RowStyle CssClass="myrow" />
<AlternatingRowStyle CssClass="myrow" />
<Columns>
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" />

</Columns>
</asp:GridView>









share|improve this question

























  • It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

    – jdweng
    Jan 2 at 17:09











  • That still did not work.

    – Shane
    Jan 2 at 17:19











  • Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

    – jdweng
    Jan 2 at 17:26











  • No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

    – Shane
    Jan 2 at 17:47






  • 1





    You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

    – jdweng
    Jan 2 at 17:58














0












0








0








I am trying to get outlook calendar items using Microsoft.Office.Interop.Outlook to a gridview table in ASP.NET. I have no problem getting the data to a listbox but I need to have it in a gridview table format.



I'm not getting any errors when running the code, it's just not showing any data.



        public void GetAllCalendarItems()
{
DataTable calendardata = new DataTable();
calendardata.Columns.Add("Subject", typeof(string));
calendardata.Columns.Add("StartDate", typeof(DateTime));

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
Recipient outlookAccount = oApp.Session.CreateRecipient("outofoffice");
CalendarFolder = mapiNamespace.GetSharedDefaultFolder(outlookAccount, OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{

DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;

foreach (DataRow dr in calendardata.Rows)
{
tblCalendar.DataSource = calendardata;
tblCalendar.DataBind();
}
}
}


Here is the asp.net code:



        <asp:GridView ID="tblCalendar" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped" Visible="true">
<RowStyle CssClass="myrow" />
<AlternatingRowStyle CssClass="myrow" />
<Columns>
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" />

</Columns>
</asp:GridView>









share|improve this question
















I am trying to get outlook calendar items using Microsoft.Office.Interop.Outlook to a gridview table in ASP.NET. I have no problem getting the data to a listbox but I need to have it in a gridview table format.



I'm not getting any errors when running the code, it's just not showing any data.



        public void GetAllCalendarItems()
{
DataTable calendardata = new DataTable();
calendardata.Columns.Add("Subject", typeof(string));
calendardata.Columns.Add("StartDate", typeof(DateTime));

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
Recipient outlookAccount = oApp.Session.CreateRecipient("outofoffice");
CalendarFolder = mapiNamespace.GetSharedDefaultFolder(outlookAccount, OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{

DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;

foreach (DataRow dr in calendardata.Rows)
{
tblCalendar.DataSource = calendardata;
tblCalendar.DataBind();
}
}
}


Here is the asp.net code:



        <asp:GridView ID="tblCalendar" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped" Visible="true">
<RowStyle CssClass="myrow" />
<AlternatingRowStyle CssClass="myrow" />
<Columns>
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" />

</Columns>
</asp:GridView>






c# asp.net gridview datatable outlook






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 21:28







Shane

















asked Jan 2 at 16:36









ShaneShane

9418




9418













  • It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

    – jdweng
    Jan 2 at 17:09











  • That still did not work.

    – Shane
    Jan 2 at 17:19











  • Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

    – jdweng
    Jan 2 at 17:26











  • No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

    – Shane
    Jan 2 at 17:47






  • 1





    You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

    – jdweng
    Jan 2 at 17:58



















  • It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

    – jdweng
    Jan 2 at 17:09











  • That still did not work.

    – Shane
    Jan 2 at 17:19











  • Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

    – jdweng
    Jan 2 at 17:26











  • No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

    – Shane
    Jan 2 at 17:47






  • 1





    You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

    – jdweng
    Jan 2 at 17:58

















It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

– jdweng
Jan 2 at 17:09





It is possible the Calendar is not getting repainted. Try setting DataSource to null : tblCalendar.DataSource = null;tblCalendar.DataSource = dt;

– jdweng
Jan 2 at 17:09













That still did not work.

– Shane
Jan 2 at 17:19





That still did not work.

– Shane
Jan 2 at 17:19













Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

– jdweng
Jan 2 at 17:26





Dos the DataTable dt contain data? Put break point after data is put into table. Then hover over dt variable, click on down arrow and then select Data Table Visualizer.

– jdweng
Jan 2 at 17:26













No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

– Shane
Jan 2 at 17:47





No, it is not. There is data in row["Subject"] = item.Subject; - but not in DataRow dr. I'm not sure how to get the data there.

– Shane
Jan 2 at 17:47




1




1





You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

– jdweng
Jan 2 at 17:58





You already put the rows into the datatable using DataRow row = calendardata.NewRow(); So you only need one foreach loop. Then after the foreach you just need one statement : tblCalendar.DataSource = calendardata;

– jdweng
Jan 2 at 17:58












2 Answers
2






active

oldest

votes


















0














Code should look like this :



foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;
}
tblCalendar.DataSource = calendardata;





share|improve this answer
























  • I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

    – Shane
    Jan 3 at 19:53



















0














This resolved my issue:



dt.Rows.Add(new Object { item.Subject, item.Start.Date }); 
tblCalendar.DataBind();`





share|improve this answer
























  • I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

    – jdweng
    Jan 3 at 20:38











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009928%2fgetting-outlook-calendar-items-to-grid-view-in-asp-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Code should look like this :



foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;
}
tblCalendar.DataSource = calendardata;





share|improve this answer
























  • I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

    – Shane
    Jan 3 at 19:53
















0














Code should look like this :



foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;
}
tblCalendar.DataSource = calendardata;





share|improve this answer
























  • I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

    – Shane
    Jan 3 at 19:53














0












0








0







Code should look like this :



foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;
}
tblCalendar.DataSource = calendardata;





share|improve this answer













Code should look like this :



foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
DataRow row = calendardata.NewRow();
row["Subject"] = item.Subject;
row["StartDate"] = item.Start.Date;
}
tblCalendar.DataSource = calendardata;






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 0:02









jdwengjdweng

17.9k2817




17.9k2817













  • I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

    – Shane
    Jan 3 at 19:53



















  • I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

    – Shane
    Jan 3 at 19:53

















I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

– Shane
Jan 3 at 19:53





I was able to get it working by using the following: dt.Rows.Add(new Object { item.Subject, item.Start.Date }); and then - tblCalendar.DataBind(); Thank you for your suggestions.

– Shane
Jan 3 at 19:53













0














This resolved my issue:



dt.Rows.Add(new Object { item.Subject, item.Start.Date }); 
tblCalendar.DataBind();`





share|improve this answer
























  • I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

    – jdweng
    Jan 3 at 20:38
















0














This resolved my issue:



dt.Rows.Add(new Object { item.Subject, item.Start.Date }); 
tblCalendar.DataBind();`





share|improve this answer
























  • I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

    – jdweng
    Jan 3 at 20:38














0












0








0







This resolved my issue:



dt.Rows.Add(new Object { item.Subject, item.Start.Date }); 
tblCalendar.DataBind();`





share|improve this answer













This resolved my issue:



dt.Rows.Add(new Object { item.Subject, item.Start.Date }); 
tblCalendar.DataBind();`






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 19:56









ShaneShane

9418




9418













  • I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

    – jdweng
    Jan 3 at 20:38



















  • I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

    – jdweng
    Jan 3 at 20:38

















I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

– jdweng
Jan 3 at 20:38





I don't think the first line does anything. There is no table dt in your code unless you meant table tblCalendar.

– jdweng
Jan 3 at 20:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009928%2fgetting-outlook-calendar-items-to-grid-view-in-asp-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith