filestream

How does one use FileStream to append to a file without an exclusive lock?

What I'm trying to do with FileStream in C#/.NET is to open two streams: one appending to a file and the other reading those writes asynchronously (for unit testing some network connection handling code). I can't figure out how to get the writer stream to open the file in non-exlusive locking mode and thus the code always throws an exce...

What's the best way to write a short[] array to a file in C#?

I have an array of shorts (short[]) that I need to write out to a file. What's the quickest way to do this? ...

Writing to a FileStream behaves strangely, as observed by process monitor

I'm using FileStream to write to a file, and watching the underlying system calls using Process Monitor. I'm having trouble with some file locking issues in a production deployment, so I'm looking at the details closely. This sample code: using (FileStream fs = new FileStream("c:\\temp\\test.txt", FileMode.Create, FileAccess.W...

How to correctly open a FileStream for usage with an XDocument

I want to append some nodes to an xml document using Linq2XML. The file in question is being used by other processes and they should be able to read the file while I update it. So I came up with this solution, which obviously isn't the correct way (The method doc.Save() fails and says that another process is using the file): using (File...

Can I use MediaPlayer to play sounds from a stream? Or, can I use an URI to access a filestream?

I'm using System.Windows.Media.MediaPlayer to play some sounds, and I would like to load these sounds from a ZIP file. It would be nice to be able to load these files as a stream directly from the zip file instead of having to unzip to a temp directory. However, MediaPlayer.open only accepts an URI. So, is there a way to create a URI t...

The filestream of sql server 2008

The FILESTREAM feature of SQL Server 2008, allows storage of and efficient access to BLOB data using a combination of SQL Server 2008 and the NTFS file system. When insert a row on a table which contains varbinary column with filestream attribute, the file (data) is stored directly on the file system and assigned the new name (e.g. 0000...

How to ensure all data has been physically written to disk?

I understand that .NET FileStream's Flush method only writes the current buffer to disk, but dependent on Windows' disk driver and the hard disk firmware this is no guarantee that the data is actually physically written to disk. Is there a .NET or Win32 method that can give me this guarantee? So if there is power loss one nanosecond aft...

Completely overwriting a file with Velocity / NVelocity

I am trying to use NVelocity templates in a .Net application: using a template to output results to a file. It all seems to work fine except for the fact that the output is never fully overwritten. If my file is 100 characters long and the template only renders 20 characters, the last 80 characters are never altered! Code sample: Fi...

C# Reading 'Zip' files with FileStream

I have written a program that will etablish a network connection with a remote computer using TCPClient I am using it to transfer files in 100k chunks to a remote .net application and it inturn then writes them to the HardDrive. All file transfers work good except when it comes to ZIP files - it is curious to note that the reasembled fil...

Best way to handle a large download site?

I currently have a download site for my school that is based in .net. We offer anything from antivirus, autocad, spss, office, and a number of large applications for students to download. It's currently setup to handle them in 1 of 2 ways; anything over 800 megs is directly accessable through a seperate website while under 800 megs is...

Larger File Streams using C#

Hey All, There are some text files(Records) which i need to access using C#.Net. But the matter is those files are larger than 1GB. (minimum size is 1 GB) what should I need to do? What are the factors which I need to be concentrate on? Can some one give me an idea to over come from this situation. ...

Blocking read from FIFO via ifstream object

I open a FIFO file as ifstream. As soon as the object is created the thread is blocked until I send something into the FIFO (which is OK for me). I then call getline() to get the data from stream. How do I read-block the thread again until more data is written into FIFO file? Thanks ...

Use a MemoryStream with a function that expects a Filestream

I have some functions here that for example are defined as private int WriteLogikParameterTyp(FileStream filestream) which i can not change. I want them to write into a MemoryStream Object. Is this possible? ...

PHP Pass File Handle to user so that file downloads & saves to their machine

Hello all, I am downloading a file from another server. I wish to push this file to my users rather than saving it to my server. In other words, pass them the file handle so it just passes through my server and saves to their machine. How can I do this? I have this so far: $handle = fopen($_GET['fileURL'], 'r'); $filename = stream_ge...

Possible reasons for FileStream.Write() to throw an OutOfMemoryException?

I have 10 threads writing thousands of small buffers (16-30 bytes each) to a huge file in random positions. Some of the threads throw OutOfMemoryException on FileStream.Write() opreation. What is causing the OutOfMemoryException ? What to look for? I'm using the FileStream like this (for every written item - this code runs from 10 dif...

Convert MemoryStream to FileStream creates hundreds of identical files?

I am accessing a httpwebrequest that returns a pdf file as the response. I am reading that response into a memory stream, and later on converting to a file. The problem is, is that hundreds of files are being created. Not sure why, I've tried many ways, and all do the same... This is the first method which returns the memorystream. ...

Read excel file from a stream

Hi! I need a way to read a Excel file from a stream. It doesn't seem to work with the ADO.NET way of doing things. The scenario is that a user uploads a file through a FileUpload and i need to read some values from the file and import to a database. For several reasons i CAN'T save the file to disk, and there is no reason to do so eig...

Asynchronous operations performance

One of the features of asynchronous programming in .NET is saving threads during long running operation execution. The FileStream class can be setup to allow asynchronous operations, that allows running (e.g.) a copy operation without virtually using any threads. To my surprise, I found that running asynchronous stream copy performs not ...

How to both Read/Write File in C#

I want to both read and write to a file. this dont works static void Main(string[] args) { StreamReader sr = new StreamReader(@"C:\words.txt"); StreamWriter sw = new StreamWriter(@"C:\words.txt"); } How do both read and write file in C#? ...

Using C# is it possible to test if a lock is held on a file

BACKGROUND: I use an offset into a file and the Filestream lock/unlock menthods to control read/write access. I am using the following code to test if a lock is currently held on the file try { fs.Lock( RESERVED_BYTE, 1 ); fs.Unlock( RESERVED_BYTE, 1 ); rc = 1; } catch { rc = 0; } QUESTION: My goal is to eliminate the try/c...