Click here to Skip to main content
15,920,030 members
Home / Discussions / C#
   

C#

 
GeneralRe: need simple accounting software source code in C#.... Pin
R.Sheikh24-Oct-13 23:40
R.Sheikh24-Oct-13 23:40 
GeneralRe: need simple accounting software source code in C#.... Pin
Dave Kreskowiak25-Oct-13 3:27
mveDave Kreskowiak25-Oct-13 3:27 
AnswerSTOP SPAMMING THE FORUMS Pin
leckey10-Nov-08 11:08
leckey10-Nov-08 11:08 
GeneralRe: STOP SPAMMING THE FORUMS Pin
lincyang10-Nov-08 18:35
lincyang10-Nov-08 18:35 
QuestionPre - Information for user before mainapplication starts Pin
JuergenLissmann9-Nov-08 22:03
JuergenLissmann9-Nov-08 22:03 
AnswerRe: Pre - Information for user before mainapplication starts Pin
Giorgi Dalakishvili9-Nov-08 22:11
mentorGiorgi Dalakishvili9-Nov-08 22:11 
AnswerRe: Pre - Information for user before mainapplication starts Pin
AhsanS9-Nov-08 22:11
AhsanS9-Nov-08 22:11 
QuestionHow to get the Count of attachment in a particular mail Pin
Neeraj Kr9-Nov-08 21:04
Neeraj Kr9-Nov-08 21:04 
Below is the code I am using to get the unread emails, checking their subject and processing accordingly. The problem is that I am getting the exception "System.ArgumentException" which says "Cannot find the method on the object instance" on the line where I am trying to find out the number of attachments in a mail. The line is -

iAttachCnt = mailItem.Attachments.Count;

// Here is the complete code
private void WeeklyExpenses_Load(object sender, EventArgs e)
        {
           Outlook.NameSpace oNs;
           Outlook.MAPIFolder oFldr;

            int iAttachCnt;

            DirectoryInfo di = new DirectoryInfo(System.Environment.CurrentDirectory.ToString() + "\\centralexpenses\\" + DateTime.Now.ToString("yyMMdd") + "\\");
            if (!di.Exists)
            {
                di.Create();
            }
            string strPath = System.Environment.CurrentDirectory.ToString() + "\\centralexpenses\\" + DateTime.Now.ToString("yyMMdd") + "\\";
            //MessageBox.Show(strPath);
            try
            {
                String sClassComp = "IPM.Note";
                oOutlook = new Outlook.Application();
                
                oNs = oOutlook.GetNamespace("MAPI");
                //Outlook.Recipient rcFieldAudit = default(Outlook.Recipient);
                //rcFieldAudit = oNS.CreateRecipient("Administrator");
                //getting mail folder from inbox
                //oFldr = oNs.GetSharedDefaultFolder(rcFieldAudit, Outlook.OlDefaultFolders.olFolderInbox);
                oFldr = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.Items newMailItems = null;
                Outlook.MailItem mailItem = null;
                Outlook.Attachments atmt = null;
                newMailItems = oFldr.Items.Restrict("[unread] = true");
                // loop over the new mails
                   
                foreach (object item in newMailItems)
                {
                    if (((Outlook.MailItem)item).MessageClass == sClassComp)
                    {
                        // cast from object to Outlook.MailItem
                        mailItem = (Outlook.MailItem)item;
                        if (mailItem.SenderEmailType == "EX")
                        {
                            string emailString = X4UMapi.GetMessageSenderAddress(mailItem.MAPIOBJECT).ToString();
                            int lastindex = emailString.LastIndexOf("=") + 1;
                            empEmail = emailString.Substring(emailString.LastIndexOf("=") + 1, ((emailString.Length - 1) - emailString.LastIndexOf("="))) + "@phfi.org";
                        }
                        else
                        {
                            empEmail = mailItem.SenderEmailAddress.ToString();
                        }

                        // loop over the attachments
                        iAttachCnt = mailItem.Attachments.Count;
                        if (mailItem.Subject.ToString().ToUpper().Contains("Weekly Expenses") && iAttachCnt != 0)
                        {
                            foreach (Outlook.Attachment attachment in mailItem.Attachments)
                            {
                                // get the attachment filename and determine the type
                                string filename = attachment.FileName.ToLower();

                                if (filename.EndsWith(".xls"))
                                {
                                    //Mark Mail as Read
                                    mailItem.UnRead = false;
                                    // save tempfile for printing
                                    filename = strPath + attachment.FileName;
                                    flName = attachment.FileName;
                                    // save the attachment
                                    attachment.SaveAsFile(filename);
                                    // release the COM object
                                    Marshal.ReleaseComObject(attachment);
                                    openandProcessExpenses(strPath, flName, empEmail);
                                    smMail.sendMail(empName, empEmail, errorDescription);
                                }
                            }
                        }
                        else
                        {
                            if (iAttachCnt == 0)
                            {
                                errorDescription = "The Mail Sent By You is Not a Valid Email for Processing The Centrally Incurred Expenses As It Does Not Contain Any Attachments";
                            }
                            smMail.sendMail(empName, empEmail, errorDescription);
                        }
                    }
                }

            }
            catch (System.Exception ex)
            {
                //Response.Write("Execption generated:" + ex.Message);
            }
            finally
            {
                GC.Collect();
                oFldr = null;
                oNs = null;
                oOutlook = null;
            }
        }


-----Have A Nice Day-----

AnswerRe: How to get the Count of attachment in a particular mail Pin
Wendelius10-Nov-08 7:26
mentorWendelius10-Nov-08 7:26 
QuestionDatagrid problem while loading XML data Pin
DJ2459-Nov-08 20:14
DJ2459-Nov-08 20:14 
AnswerRe: Datagrid problem while loading XML data Pin
J a a n s9-Nov-08 20:31
professionalJ a a n s9-Nov-08 20:31 
GeneralRe: Datagrid problem while loading XML data Pin
Giorgi Dalakishvili9-Nov-08 20:38
mentorGiorgi Dalakishvili9-Nov-08 20:38 
GeneralRe: Datagrid problem while loading XML data Pin
DJ2459-Nov-08 21:25
DJ2459-Nov-08 21:25 
Questionmove a form Pin
prasadbuddhika9-Nov-08 19:43
prasadbuddhika9-Nov-08 19:43 
AnswerRe: move a form Pin
Giorgi Dalakishvili9-Nov-08 19:48
mentorGiorgi Dalakishvili9-Nov-08 19:48 
AnswerRe: move a form Pin
AhsanS9-Nov-08 20:03
AhsanS9-Nov-08 20:03 
GeneralRe: move a form Pin
prasadbuddhika9-Nov-08 23:25
prasadbuddhika9-Nov-08 23:25 
AnswerRe: move a form Pin
#realJSOP9-Nov-08 23:51
professional#realJSOP9-Nov-08 23:51 
QuestionDoes anybody face any type of issues with Logging and Instrumentation Application Block? please share. Pin
Member 23244839-Nov-08 18:56
Member 23244839-Nov-08 18:56 
AnswerRe: Does anybody face any type of issues with Logging and Instrumentation Application Block? please share. Pin
AhsanS9-Nov-08 20:04
AhsanS9-Nov-08 20:04 
QuestionThumnails in C# Pin
Member 14902599-Nov-08 18:18
Member 14902599-Nov-08 18:18 
AnswerRe: Thumnails in C# Pin
Guffa9-Nov-08 19:18
Guffa9-Nov-08 19:18 
AnswerRe: Thumnails in C# Pin
N a v a n e e t h9-Nov-08 19:54
N a v a n e e t h9-Nov-08 19:54 
GeneralRe: Thumnails in C# Pin
Guffa9-Nov-08 23:23
Guffa9-Nov-08 23:23 
GeneralRe: Thumnails in C# Pin
N a v a n e e t h10-Nov-08 0:51
N a v a n e e t h10-Nov-08 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.