I apologize if you thought I meant your code was messy, I was use "mess of
code" with the meaning of a "whole lot of code to look at".
I'd recommend stepping the code and seeing exactly where and when that
second entry in the database is being made. Are the attachment details table
entries also duplicated? In that case it might be worth seeing if your
procedure is being called more than once per item, more often than you
expect. You can put a Debug.WriteLine() line in that event handler that
notes that the event has fired to help you keep track of that. If that's the
case then you can use a flag to indicate that you've already handled the
event for that item.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"anindasen_0609" wrote in message
...
[i]
"I can't tell from that mess of code where you're recording the email in
the
database"
-- If it is a mess can you tell me what makes you feel so and some
suggestions for improvement?
"but if it's in the line that starts with
cmsServ.InsertCommunicationAttachment then that's inside the for loop and
will cause the same item to be inserted once for each attachment in the
email."
-- As you can see if you observe a little closely that saving into the
database is not inside the for loop. The one that is getting saved inside
the
loop is to the attachment details table as below:
try
{
CMSService cmsServ = new CMSService();
newCommunicationID =
cmsServ.InsertCommunication(fromContactID, fromEmailID, toAddress,
ccAddress,
bccAddress, newItem.Subject, newItem.HTMLBody, Convert.ToInt32(userID),
DateTime.Now, 0, newItem.Body, GUIDFolderName);
//Save attachments if any
if (newItem.Attachments.Count 0)
{
ftpConnect();
ftp.ChDir("OutlookAttachments");
ftp.MkDir(GUIDFolderName);
ftp.ChDir(GUIDFolderName);
for (int i = 1; i = newItem.Attachments.Count; i++)
{
newItem.Attachments[i].SaveAsFile(sourcePath + @"\"
+ newItem.Attachments[i].FileName);
ftp.Put(sourcePath + @"\" +
newItem.Attachments[i].FileName, newItem.Attachments[i].FileName);
File.Delete(sourcePath + @"\" +
newItem.Attachments[i].FileName);
cmsServ.InsertCommunicationAttachment(GUIDFolderNa me, newCommunicationID,
GUIDFolderName + @"\" + newItem.Attachments[i].FileName,
newItem.Attachments.FileName);
}
ftp.Quit();
}
}
catch (Exception ex)
{
string errorInfo = (string)ex.Message.Substring(0, 11);
}
}
Your comment regarding dot operator has been noted. Thanks.
Regards,
Aninda