473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Post item on outlook

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[i];

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

Dec 3 '05 #1
0 1589

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ramón | last post by:
why am I not allowed to intanstiate a new task item? TaskItem task_DC = new TaskItemClass(); This is the erro I get when building: error CS0122:...
0
by: William | last post by:
Hi there, Is there anybody here who ever create outlook task item from asp .net script successfully ? Actually I've created the script for creating the task, and it run successfully from the...
1
by: elziko | last post by:
Everytime I use this code: Dim objOutlook As New Outlook.Application Dim objNameSpace As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objJournalEntry As Outlook.JournalItem =...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
by: Roger | last post by:
I have a program that goes through an outlook inbox. Dim myItem as Outlook.MailItem For i = 1 to items.count myItem = myolap.items(i) ... .... .... Next
0
by: NeilS | last post by:
Hi all. I'm a newbie at VB.net, so please forgive me if this is well documented somewhere. I've found some sample code on the MS site for iterating over each unread item in the Inbox, and...
4
by: John A. Bailo | last post by:
After upgrading from Outlook 2000 to the 2003 object model, some of my Outlook automation code no longer functions. For example, in 2000, I used to be able to loop through a list of .Items in a...
9
by: JBuckner | last post by:
My macro uses the Send Object (VBA Item.Send) function to email a spreadsheet to an Outlook contact list. I want the function to be completely automatic but Outlook displays a security warning...
1
by: chrisli | last post by:
Hey, i have written this code to read all Outlook Appointments from another user and fill them into my DGV. Public Sub ReadOtherUserAppointment(ByVal UserName As String) Dim objolApp...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.