p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   ASP.NET 3.5 Professionals (http://p2p.wrox.com/asp-net-3-5-professionals-352/)
-   -   'System.Web.HttpApplicationState' does not contain a definition for 'Session' (http://p2p.wrox.com/asp-net-3-5-professionals/79081-system-web-httpapplicationstate-does-not-contain-definition-session.html)

sid April 18th, 2010 11:52 AM

'System.Web.HttpApplicationState' does not contain a definition for 'Session'
 
Below is the code to obtain Members of an Exchange Distribution List.I am using this as namespace Outlook = Microsoft.Office.Interop.Outlook;to get members from Outlook.

private void GetDistributionListMembers()
{

//using app = (HttpContext.Current.ApplicationInstance);

//if (app != null)

//{
Outlook.SelectNamesDialog snd = Application.Session.GetSelectNamesDialog();
Outlook.AddressLists addrLists = Application.Session.AddressLists;

foreach (Outlook.AddressList addrList in addrLists)
{
if (addrList.Name == "All Groups")
{
snd.InitialAddressList = addrList;
break;
}
}
snd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo;
snd.ToLabel = "D/L";
snd.ShowOnlyInitialAddressList = true;
snd.AllowMultipleSelection = false;
snd.Display();
if (snd.Recipients.Count > 0)
{
Outlook.AddressEntry addrEntry = snd.Recipients[1].AddressEntry;
if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistribut ionListAddressEntry)
{
Outlook.ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList();
Outlook.AddressEntries addrEntries = exchDL.GetExchangeDistributionListMembers();
if (addrEntries != null)
foreach (Outlook.AddressEntry exchDLMember
in addrEntries)
{
//Debug.WriteLine(exchDLMember.Name);
Response.Write(exchDLMember.Name);
}
}
}
//}
}

This is the error which I am getting:
'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?)

Requirement is to get all members of Outlook distribution list & mail them on submit of form button.

Urgent help needed

Imar April 18th, 2010 01:36 PM

Looks like Application is referring to the standard ASP.NET Application object (of type HttpApplicationState). You probably need to prefix it with the namespace that contains the Application class you're trying to use.

Cheers,

Imar

sid April 19th, 2010 12:44 AM

'System.Web.HttpApplicationState' does not contain a definition for 'Session'
 
Hi Imar,

Below are the namespaces I am using

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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 System.Xml.Linq;
using AbsenceTrackingSystem;
using Outlook = Microsoft.Office.Interop.Outlook;


I tried as below in the code:

AbsenceTrackingSystem app = (HttpContext.Current.ApplicationInstance);

Its telling AbsenceTrackingSystem is a namespace & used as a type.

could you help me by writing that piece of code in the namespace or in the code below:

private void GetDistributionListMembers()
{

AbsenceTrackingSystem app = HttpContext.Current.ApplicationInstance;

if (app != null)
{
Outlook.SelectNamesDialog snd = Application.Session.GetSelectNamesDialog();
Outlook.AddressLists addrLists = Application.Session.AddressLists;
foreach (Outlook.AddressList addrList in addrLists)
{
if (addrList.Name == "All Groups")
{
snd.InitialAddressList = addrList;
break;
}
}
snd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo;
snd.ToLabel = "D/L";
snd.ShowOnlyInitialAddressList = true;
snd.AllowMultipleSelection = false;
snd.Display();
if (snd.Recipients.Count > 0)
{
Outlook.AddressEntry addrEntry = snd.Recipients[1].AddressEntry;
if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistribut ionListAddressEntry)
{
Outlook.ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList();
Outlook.AddressEntries addrEntries = exchDL.GetExchangeDistributionListMembers();
if (addrEntries != null)
foreach (Outlook.AddressEntry exchDLMember
in addrEntries)
{
Debug.WriteLine(exchDLMember.Name);
Response.Write(exchDLMember.Name);
}
}
}
}
}

Imar April 19th, 2010 03:32 AM

Hi there,

I think the start of the code is fine; but thiss isn't:

Code:

Outlook.SelectNamesDialog snd = Application.Session.GetSelectNamesDialog();
Here, Application refers to the Application of ASP.NET. You need to prefix Application with something from the Oulook namespace (at least, that's what my guess is; I don't know this code so I don't know where your Application is supposed to come from). E.g. something like this:

Code:

Outlook.SelectNamesDialog snd = SomeNamespaceHereApplication.Session.GetSelectNamesDialog();
Hope this helps,

Imar


All times are GMT -4. The time now is 11:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.