Im writing a small web application and what I'd like to do is open a
file, read the contents into memory and then close the file as fast as
I can to free up the file for the next user. Once the file is loaded
into memory and subsequently closed, i would use the contents of the
file (now loaded into memory) to perform some quick processing. Any
idea how best to do this?
Thanks in advance for your help! 3 1476
Hi FerrisUML,
Opening, closing files are done using System.IO.File. Storing the content
in memory can be done in any number of ways, like string, byte[] or
MemoryStream.
As for doing this in web applications you need to be aware of restrictions
for accessing the file system, which by default is limited to the web
application root folder and its subfolders.
If you need to access other folders, either open up for this folder/file by
adding read/write permissions to aspnet, or change the account used to run
the web application to something that has access to the file
--
Happy Coding!
Morten Wennevik [C# MVP]
"FerrisUML" wrote:
Im writing a small web application and what I'd like to do is open a
file, read the contents into memory and then close the file as fast as
I can to free up the file for the next user. Once the file is loaded
into memory and subsequently closed, i would use the contents of the
file (now loaded into memory) to perform some quick processing. Any
idea how best to do this?
Thanks in advance for your help!
On Mon, 10 Mar 2008 01:30:24 -0700, Jon Skeet [C# MVP] <sk***@pobox.co m>
wrote:
I'd go beyond that - I'd keep reading regardless of the file's original
length:
http://pobox.com/~skeet/csharp/readbinary.html
I don't know about that. The OP suggested he wants to read the file as
fast as possible. To me, this means not performing any allocations or
other "optional" work while the file is actually open. Making the code
flexible enough to deal with an indetermine file length means introducing
potential overhead.
There is also the implication, though he doesn't state it explicitly, that
the files have been completely written as of the moment he wants to
process them. So coding that flexibility might not be needed in any case.
Pete
On Mon, 10 Mar 2008 05:03:04 -0700, Michael D. Ober
<obermd.@.alum. mit.edu.nospam. wrote:
Using a filestream has another advantage, you can open it
readonly/share-read so that other processes can also open it the same
way, making the locking issue completely go away.
Agreed. I took it as implied that for some reason the OP needed sole
access to the file at the moment he's reading/processing it. But yes, if
you can change the original problem definition, there are better ways to
deal with this than reading the whole file into memory all at once.
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas |
last post by:
after spending countless hours trying, i give up and hope to get some help
in here.
on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm
trying to read a file from an UNC path with a FSO:
Set myFile =
Server.CreateObject("Scripting.FileSystemObject").GetFile("\\server2\myshare\myfile.txt")
this fails with an Permission Denied.
here's the deal:
|
by: prodirect |
last post by:
Hi all,
I hope someone can help me. I've recently created a database and wanted to
put it up on an ftp sight so that multiple people could access the same
tables at the same time from different geographical locations. I have been
completely unsucessful in acheiving this goal so far however.
Things I have tried:
Create a shortcut to ftp sight via browser then tried to map local drive to
|
by: Paulos |
last post by:
Hi
Has anyone any experience of accessing .CSV files with ADO.NET and C#?
All I want to do is open and read a number of them.
I have search the help files, the MDSN and all the books I have but so far,
I have found no mention of how to do this.
Any help/sample code would be appreciated
|
by: Joergen Bech |
last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running
application on a web server outside of my control, but only the first
time I run it:
1. After a long period of inactivity (or updating the code-behind dll)
accessing any aspx page in the application causes the application
to run for the first time. Some of the initialization involves
reading and writing some text and xml files using simple streamreader
and streamwriter...
|
by: Khalique |
last post by:
I have built a web service whose purpose is to copy files from a secure place
to client machine and vice versa. The problem I am having is perhaps related
to permissions and access rights.
For testing purposes, the secure place is setup on the client machine.
The client (window app) calls the web service (on a different machine) and
connects successfully to the web service. However, when client calls a method
that copies the file from...
| |
by: sonu |
last post by:
I have following client side code which i have used in my asp.net
project
SummaryFeatured Resources from the
IBM Business Values Solution Center
WHITEPAPER :
CRM Done Right
Improve the likelihood of CRM success from less than 20 percent to 60
percent.
WHITEPAPER :
|
by: Gerhard |
last post by:
I have an application that needs to be able to upload documents that can
latter be accessed and opened by a hyperlink. I can do this easliy if I
store the files in a subdirectory in the application, but we will be using
multiple web servers, so the files need to be stored on a common file server.
Saving them is easy enough, but how do I point a hyperlink at a file on a
file server that is different from the web server?
Could you please...
|
by: kosmodisk |
last post by:
Hi,
I'm having problem accessing javascript-created elements from opened
window. This occurs only when I'm including another files in opened
window, javascript or css. When I comment out "<link>" and "<script>"
(point (0)), the script works fine.
The opening window itself (point (1)) can access the object. When page
has been loaded, then I can access the object also (point (3)). The
script does find included files (debug_test2.css and...
|
by: leenadiwan |
last post by:
Friends,
Im having problem with accessing a JS file placed in another folder from a JSP popup.
I tried all the following:
<SCRIPT LANGUAGE="JavaScript1.1"
SRC="../js/SpellCheckForm.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.1"
SRC="/js/SpellCheckForm.js"></SCRIPT>
|
by: Adam McCormack |
last post by:
Good morning, I hope I'm not repeating a post, but I did try to search for the topic before asking.
I am trying to resolve an issue that has come up as a result of planned migration from a single server solution to a distributed solution. A site (and interrelated batch processing scripts) has been running on a single server (IIS 6, win 2003) to two machines both are IIS 6, win 2003, the machines are as follows:
box1: Webserver
box2:...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |