Post item on outlook

R

ratnakarp

Is there any way i can improve on this code? If i run this application
by giving the detials of the start date and end date in the range of
15 days, it's taking 3 mins. I'm looking for a code which can run
faster than this. I'm running this on asp.net 2.0. Any
suggestions/comments would be appreciated.



Default.aspx
-------------------------


<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 772px" border="0" width="100%" >
<tr>
<td colspan="3">
<strong><span style="font-size: 14pt">&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; Web Customer Care E-mail Tracking
System</span></strong></td>
</tr>
</table>
<br />
This will filter duplicate ads, cancelled ads and also retrieve
the information
for which the ads doesnt have ad id's and customer
information.<br />
<br />

</div>
<table style="width: 440px">
<tr style="background-color:Silver" >
<td>
Select Site</td>
<td style="width: 56px">
<asp:DropDownList ID="DropDownList1" runat="server"
Width="173px">
<asp:ListItem>DTI GSO Web Email</asp:ListItem>
<asp:ListItem>DTI Pilot Web
Email</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 56px">
</td>
</tr>
<tr style="background-color:Silver">
<td>
Enter Start Date</td>
<td style="width: 56px">
<asp:TextBox ID="txtStDate" runat="server"
Width="174px"></asp:TextBox></td>
<td style="width: 56px">
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtStDate"
ErrorMessage="Enter Start Date"
Width="105px"></asp:RequiredFieldValidator></td>
</tr>
<tr style="background-color:Silver">
<td style="height: 26px">
Enter End Date</td>
<td style="width: 56px; height: 26px">
<asp:TextBox ID="txtEndDate" runat="server"
Width="173px"></asp:TextBox></td>
<td style="width: 56px; height: 26px">
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtEndDate"
ErrorMessage="Enter End
Date"></asp:RequiredFieldValidator></td>
</tr>
<tr style="background-color:ThreeDShadow ">
<td>
</td>
<td style="width: 56px">
<asp:Button ID="Button1" runat="server"
Text="Submit" OnClick="Button1_Click" /></td>
<td style="width: 56px">
</td>
</tr>
</table>
<br />
<table style="width: 260px">
<tr>
<td style="height: 21px">
Mail Count</td>
<td style="width: 6px; height: 21px">
<asp:Label ID="Label1"
runat="server"></asp:Label></td>
</tr>
<tr>
<td>
Duplicate Ads</td>
<td style="width: 6px">
<asp:Label ID="Label2"
runat="server"></asp:Label></td>
</tr>
<tr>
<td>
Cancelled Ads</td>
<td style="width: 6px">
<asp:Label ID="Label3"
runat="server"></asp:Label></td>
</tr>
<tr>
<td>
Ad Without Ad ids</td>
<td style="width: 6px">
<asp:Label ID="Label4"
runat="server"></asp:Label></td>
</tr>
<tr>
<td>
Total</td>
<td style="width: 6px">
<asp:Label ID="Label5"
runat="server"></asp:Label></td>
</tr>
</table>
<br />
<asp:Table ID="tblMail" runat="server" Height="33px"
Width="53%" BorderColor="ScrollBar" BorderStyle="Solid"
BorderWidth="1px">
</asp:Table>
</form>
</body>
</html>




Default.aspx.cs
-------------------------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Outlook;
using Microsoft.Office;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

TableRow tr = new TableRow();
TableCell tc0 = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
TableCell tc4 = new TableCell();
TableCell tc5 = new TableCell();
TableCell tc6 = new TableCell();
TableCell tc7 = new TableCell();
tc0.Text = "DATE/TIME";
tc0.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(0, tc0);
tc1.Text = "12-6 AM";
tc1.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(1, tc1);
tc2.Text = "6-9";
tc2.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(2, tc2);
tc3.Text = "9-11";
tc3.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(3, tc3);
tc4.Text = "11-1";
tc4.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(4, tc4);
tc5.Text = "1-6";
tc5.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(5, tc5);
tc6.Text = "6-9";
tc6.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(6, tc6);
tc7.Text = "9-12";
tc7.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(7, tc7);
tblMail.Rows.Add(tr);
//tblMail.Rows[0].Cells[0].Text = "Date/Time";
//tblMail.Rows[0].Cells[0].Text = "12-6 AM";
//tblMail.Rows[0].Cells[0].Text = "6-9";
//tblMail.Rows[0].Cells[0].Text = "9-11";
//tblMail.Rows[0].Cells[0].Text = "11-1";
//tblMail.Rows[0].Cells[0].Text = "1-6";
//tblMail.Rows[0].Cells[0].Text = "6-9";
//tblMail.Rows[0].Cells[0].Text = "9-12";

}
protected void Button1_Click(object sender, EventArgs e)
{

Outlook._Application olApp = new Outlook.ApplicationClass();
Outlook._NameSpace olNs = olApp.GetNamespace("mapi");
Outlook._Folders oFolders;
oFolders = olNs.Folders;
Outlook.MAPIFolder oPublicFolder = oFolders["Public Folders"];
oFolders = oPublicFolder.Folders;
Outlook.MAPIFolder oAllPublicFolder = oFolders["All Public
Folders"];
oFolders = oAllPublicFolder.Folders;
Outlook.MAPIFolder oEbizFolder = oFolders["E-Business Team"];
oFolders = oEbizFolder.Folders;
Outlook.MAPIFolder oPilotFolder =
oFolders[DropDownList1.SelectedItem.Text];
Outlook.Items oItems = oPilotFolder.Items;
int countMail = 0;

int flag = 0;
TimeSpan cntdays = Convert.ToDateTime(txtEndDate.Text) -
Convert.ToDateTime(txtStDate.Text);

DateTime testDate=Convert.ToDateTime("01/01/1991");//=
Convert.ToDateTime(txtEndDate.Text );
int cnt126=0;
int cnt69 =0;
int cnt911=0;
int cnt111=0;
int cnt16 =0;
int cnt692 =0;
int cnt912=0;
int dupads = 0;
ArrayList ar = new ArrayList();
for (int i = 1; i < oItems.Count; i++)
{

Outlook.PostItem opostitem = (Outlook.PostItem)oItems;

if (opostitem.ReceivedTime >
Convert.ToDateTime(txtEndDate.Text))
{
testDate = opostitem.ReceivedTime;
continue;
}


if (testDate.Day != opostitem.ReceivedTime.Day )
{
if (flag != 0)
{
testDate = opostitem.ReceivedTime;
TableRow tr = new TableRow();
TableCell tc0 = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
TableCell tc4 = new TableCell();
TableCell tc5 = new TableCell();
TableCell tc6 = new TableCell();
TableCell tc7 = new TableCell();
tc0.Text = testDate.AddDays(1).Day.ToString() + "/"
+ testDate.AddDays(1).Month.ToString() + "/" +
testDate.AddDays(1).Year.ToString();
tc0.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(0, tc0);
tc1.Text = cnt126.ToString();
tc1.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(1, tc1);
tc2.Text = cnt69.ToString();
tc2.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(2, tc2);
tc3.Text = cnt911.ToString();
tc3.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(3, tc3);
tc4.Text = cnt111.ToString();
tc4.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(4, tc4);
tc5.Text = cnt16.ToString();
tc5.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(5, tc5);
tc6.Text = cnt692.ToString();
tc6.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(6, tc6);
tc7.Text = cnt912.ToString();
tc7.BorderStyle = BorderStyle.Inset;
tr.Cells.AddAt(7, tc7);
tblMail.Rows.Add(tr);
flag = 0;
}
else
{
testDate = opostitem.ReceivedTime ;
}
}

if (flag == 0)
{
cnt126 = 0;
cnt69 = 0;
cnt911 = 0;
cnt111 = 0;
cnt16 = 0;
cnt692 = 0;
cnt912 = 0;
}

flag = 1;

if (opostitem.Subject.StartsWith("Thank You for placing
your Ad #"))
{

if (!ar.Contains(opostitem.Subject.Substring(31, 8)))
{

ar.Add(opostitem.Subject.Substring(31, 8));

if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(0) && opostitem.ReceivedTime.Hour < Convert.ToInt32(6))
cnt126 = cnt126 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(6) && opostitem.ReceivedTime.Hour < Convert.ToInt32(9))
cnt69 = cnt69 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(9) && opostitem.ReceivedTime.Hour <
Convert.ToInt32(11))
cnt911 = cnt911 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(11) && opostitem.ReceivedTime.Hour <
Convert.ToInt32(13))
cnt111 = cnt111 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(13) && opostitem.ReceivedTime.Hour <
Convert.ToInt32(18))
cnt16 = cnt16 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(18) && opostitem.ReceivedTime.Hour <
Convert.ToInt32(21))
cnt692 = cnt692 + 1;
if (opostitem.ReceivedTime.Hour >=
Convert.ToInt32(21) && opostitem.ReceivedTime.Hour <
Convert.ToInt32(24))
cnt912 = cnt912 + 1;
countMail = countMail + 1;
}
else
{
dupads = dupads + 1;
}

}
//flag = 1;
//if (opostitem.SentOn > Convert.ToDateTime(txtStDate.Text)
&& opostitem.SentOn < Convert.ToDateTime(txtEndDate.Text))
// countMail = countMail + 1;
if (opostitem.ReceivedTime <
Convert.ToDateTime(txtStDate.Text))
break;
}

// Label1.Text = countMail.ToString();

}
}





Thanks & Regards,
Ratnakar Pedagani
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,614
Members
45,293
Latest member
Hue Tran

Latest Threads

Top