Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Read file once

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xplode144 - 11 Sep 2007 17:09 GMT
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?
John Timney (MVP) - 11 Sep 2007 20:16 GMT
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

>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?
ed@lakenine.com - 11 Sep 2007 20:20 GMT
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

> 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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.