473,473 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing files in c#

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!
Mar 10 '08 #1
3 1447
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!
Mar 10 '08 #2
On Mon, 10 Mar 2008 01:30:24 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
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
Mar 10 '08 #3
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
Mar 10 '08 #4

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

Similar topics

36
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...
3
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...
5
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...
0
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...
4
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...
0
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...
3
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...
3
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...
1
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" ...
6
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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
agi2029
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,...
1
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...
0
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 ...

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.