views:

18

answers:

1

hi i wrote following code for save some mails (already imported to data grid using MAPI) to selected inbox folder in button click

Outlook.MAPIFolder oMailFolder = null;
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
MailItem moveFilteredMails = null;
oMailFolder = oNS.PickFolder();         

oApp = null;
oNS = null;

List<UnreadEmails> filteredList = (List<UnreadEmails>)dgvUnreadMails.DataSource;
foreach (UnreadEmails item in filteredList)
{
    moveFilteredMails.Move(oMailFolder);
}

but after selecting inbox folder from pickfilder method it gives a exception saying that
NullReferenceExceptionException was unhandled and Object reference not set to an instance of an object.

pls help to find the error

A: 

You wrote moveFilteredMails = null.

Since moveFilteredMails is null, you're getting a NullReferenceException when you try to move an item into it.

SLaks
ok i got it but cant compile without assigning a value it gives Error Use of unassigned local variable 'moveFilteredMails'. pls tell me wht i have to do ..
kasunmit
You need to assign a non-`null` value to `moveFilteredMails`.
SLaks