Click here to Skip to main content
15,915,076 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code is:

C#
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Outlook;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Configuration; 
using System.Xml.Linq;
using System.Web.Security;
using Outlook = Microsoft.Office.Interop.Outlook;




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

    protected void  Button1_Click(object sender, EventArgs e)
{
    Microsoft.Office.Interop.Outlook.Application nOutlook;
    Microsoft.Office.Interop.Outlook.NameSpace oNs;
    Microsoft.Office.Interop.Outlook.MAPIFolder oFldr;
 Microsoft.Office.Interop.Outlook.MAPIFolder Register=null;
    try
    {
        //string folderPath =Application.Session.DefaultStore.GetRootFolder().FolderPath+ @"\Contacts\Key Contacts";
        nOutlook = new Microsoft.Office.Interop.Outlook.Application();
        oNs = nOutlook.GetNamespace("MAPI");
        //Outlook.SelectNamesDialog snd = OutlookApplication.Session.GetSelectNamesDialog();
        Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = Application.Session.DefaultStore.GetDefaultFolder();
     
            
        Microsoft.Office.Interop.Outlook.MAPIFolder processedFolder = null;
        foreach (Microsoft.Office.Interop.Outlook.MAPIFolder folder in rootFolder.Folders)
        {
            if (folder.Name == "Processed")
            {
                processedFolder = folder;
                break;
            }
        }


        //getting mail folder from inbox
        oFldr = oNs.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
  //Register = oNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.r
        Response.Write("Total Mail in Inbox :" + oFldr.Items.Count + " ");
        Response.Write("Total Unread items = " + oFldr.UnReadItemCount);
        foreach (Microsoft.Office.Interop.Outlook.MailItem oMessage in oFldr.Items)
        {
            StringBuilder str = new StringBuilder();
            str.Append("<table><tr><td>Sender :</td><td>");
            str.Append(oMessage.SenderEmailAddress.ToString() + "</td></tr>");

            //Define Additional Information of Message
            str.Append("<tr><td>Date :</td><td>" + oMessage.SentOn.ToShortDateString() + "</td></tr>");
            if (oMessage.Subject != null)
            {
                str.Append("<tr><td>Subject :</td><td>" + oMessage.Subject.ToString() + "</td></tr>");
               str.Append("<tr><td>SenderBy :</td><td>" + oMessage.SenderName.ToString() + "</td></tr>");
               str.Append("<tr><td>Content :</td><td>" + oMessage.Body.ToString() + "</td></tr>");
            }

            str.Append("</table><br>");
            Response.Write(str.ToString());
        }

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


Can any one tell how to give namespace for this, to clear this issue...?
Posted
Updated 22-Jul-13 19:27pm
v2
Comments
Ron Beyer 23-Jul-13 1:26am    
"tell how to give namespace for this, to clear this issue". All you gave us is a code dump without describing what the "issue" is. Maybe you can clarify what the "issue" is so we can narrow down the thousands upon thousands of potential problems to the one that you are experiencing...
v surya dev 23-Jul-13 1:28am    
While i build the application, it throws this Error:
'System.Web.HttpApplicationState' does not contain a definition for 'Session' and no extension method 'Session' accepting a first argument of type 'System.Web.HttpApplicationState' could be found (are you missing a using directive or an assembly reference?)

This is only My issue....
Ron Beyer 23-Jul-13 1:49am    
And exactly what line from above do you get this error on?
v surya dev 23-Jul-13 2:45am    
Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = Application.Session.DefaultStore.GetDefaultFolder();


I am getting this error from this line of code 'Session'.....

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900