473,416 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How do you access an application variable from a class?

Stu
Hi,

If I try to access an application variable from a class I get the error
'Name Application is not declared'.

Is ther any (fairly simple) way of getting round this or do I have to pass
the values in via properties every time I want to use them?

Thank in advance,

Stu

lang: vb.net
Nov 19 '05 #1
2 1686
HttpContext.Current.Application

note however that if your class isn't running within the context of a
webrequest, HttpContext.Current will return null...defensive coding would
be:

dim context as HttpContext = HttpContext.Current
if context is nothing then
throw new ApplicationException("must be called from a web context")
end if
'can safely access context.Application now...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Stu" <s.****@cergis.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I try to access an application variable from a class I get the error
'Name Application is not declared'.

Is ther any (fairly simple) way of getting round this or do I have to pass
the values in via properties every time I want to use them?

Thank in advance,

Stu

lang: vb.net

Nov 19 '05 #2
Stu
Many thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
HttpContext.Current.Application

note however that if your class isn't running within the context of a
webrequest, HttpContext.Current will return null...defensive coding would
be:

dim context as HttpContext = HttpContext.Current
if context is nothing then
throw new ApplicationException("must be called from a web context")
end if
'can safely access context.Application now...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Stu" <s.****@cergis.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I try to access an application variable from a class I get the error
'Name Application is not declared'.

Is ther any (fairly simple) way of getting round this or do I have to
pass
the values in via properties every time I want to use them?

Thank in advance,

Stu

lang: vb.net


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SACHIN | last post by:
I have this class as part of a Consol application. using System; namespace Bugreport { /// <summary> /// This class tries to use the Class/Struct combination. /// </summary> class Class1 {
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
3
by: Ray Stevens | last post by:
How do you access properties of the main program's class from another form? There does not apear to be an instance variable that can be used.
4
by: Al Murphy | last post by:
I have a windows application called "WindowsApplication1". I have a variable of tyoe DataSet called myDataSet as shown below: namespace WindowsApplication1 { public class Form1 :...
4
by: lars.uffmann | last post by:
Hey everyone! I am (still) working on a project that I took over from former students, so don't blame me for the criminal approach on coding *g* The problem I have is fairly easy and while I...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.