473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read file once

I have a Web application. i need to read a file once during the startup and
preserve the read data throughout the life of the application. i will to
access the data often during the page_load of the default.aspx page.

what is the best way to do so? do i need to implement a singlton object?
Sep 11 '07 #1
2 2433
Stick it in the application object, or the cache during the application
start event.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"xplode144" <xp*******@gmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have a Web application. i need to read a file once during the startup
and preserve the read data throughout the life of the application. i will
to access the data often during the page_load of the default.aspx page.

what is the best way to do so? do i need to implement a singlton object?

Sep 11 '07 #2
ed
Hi xplode144,

[This post assumes that by "Application" you're talking about the same
kinda thing that ASP.NET calls an "Application".]

For application-wide data from a file, you've already got web.config.
Use that if you can because it's easy and it's at least as fast as the
approach you're proposing.

That said, here's how to do what you asked for (broad stokes only):

Find the Application_Start event in Global.asax and put the read-file
code there. Save any values you need in the Application object:

// C#
Application["xplode144"] = "abcdef";
Application["otherfilevalue"] = 123
.. . . and so on

You'll have to restart IIS to get new values into your application
(unless you add events to watch for file changes, but that just gets
you in deeper).

Alternatives:
- web.config
- Caching (big topic but there are a lot of how-to's; it may not be
relevant to what you're trying to do)
- Just read the file each time; it doesn't take that long
You don't need a Singleton for any of the above.

HTH,
Ed
On Sep 11, 12:09 pm, "xplode144" <xplode...@gmail.comwrote:
I have a Web application. i need to read a file once during the startup and
preserve the read data throughout the life of the application. i will to
access the data often during the page_load of the default.aspx page.

what is the best way to do so? do i need to implement a singlton object?

Sep 11 '07 #3

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

Similar topics

11
8987
by: Sebastian Krause | last post by:
Hello, I tried to read in some large ascii files (200MB-2GB) in Python using scipy.io.read_array, but it did not work as I expected. The whole idea was to find a fast Python routine to read in...
3
606
by: Johnny | last post by:
Hello all, I have a 1GB XML file that I need to read once a day and I would like to get feedback to find out what is the most efficient way to go about reading this file. The application reading...
7
5037
by: KantKwitDansin1 | last post by:
I have a file "a.dat" containing 10^4 32 bit binary numbers. I need to read in these numbers and deterimine if they are prime. The primality part I will have to figure out later, but I was...
14
8490
by: Sameer | last post by:
Hello, i wish to read a file of int and store into an array dynamically... the size of memory allocated finally, should just be sufficeient to store n integers. I do not know the number of...
6
2459
by: Charlie Zender | last post by:
Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
2
2349
by: Profetas | last post by:
I have the following code that detects a <c> and </c> #include <stdio.h> main(int argc, char *argv) { FILE* fp; char data;
8
4040
by: noleander | last post by:
I've got two threads reading from one disk file (I'm using the Pthread library). I need each thread to have its own file seek pointer, so they can read from independent parts of the file. I...
4
2585
by: Antonio Tirado | last post by:
Hi, I'm using the OleDB namespace to open a CSV File. I can read the file sucessfully except for hyphenated values. My CSV File contains phone numbers and sometimes these come separated with...
3
1851
by: jao.sanien | last post by:
Hi I have a access file that need to be made to read only. And the file should be password protected if I want to edit something. So those who doesn't have the password can only read. I don't...
0
7231
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
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
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...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
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
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.