Questions tagged [filestream]

In .NET framework filestream exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations. ActionScript 3 for AIR 2 and above also uses FileStream, which supports both synchronous and asynchronous read and write operations.

2638 questions
33
votes
3 answers

stream.CopyTo - file empty. asp.net

I'm saving an uploaded image using this code: using (var fileStream = File.Create(savePath)) { stream.CopyTo(fileStream); } When the image is saved to its destination folder, it's empty, 0 kb. What could possible be wrong here? I've checked the…
user1121487
  • 2,464
  • 8
  • 36
  • 61
33
votes
5 answers

Will a using clause close this stream?

I've apparently worked myself into a bad coding habit. Here is an example of the code I've been writing: using(StreamReader sr = new StreamReader(File.Open("somefile.txt", FileMode.Open))) { //read file } File.Move("somefile.txt",…
scottm
  • 26,493
  • 22
  • 102
  • 155
32
votes
10 answers

FILESTREAM feature is disabled

I have a database set up with FILESTREAM enabled on it (if you go to Properties\Advanced on the instance, it shows that FILESTREAM is enabled). I also ran the sp_configure script on it after doing this to enable the access (to make sure it was…
Zteck
  • 337
  • 1
  • 3
  • 8
30
votes
3 answers

C equivalent to fstream's peek

I know in C++, you're able to peek at the next character by using: in.peek();. How would I go about this when trying to "peek" at the next character of a file in C?
Anthony
  • 303
  • 1
  • 3
  • 4
29
votes
5 answers

Saving openpyxl file via text and filestream

I'm building OpenPyXL into an application that expects a string containing the content of the excel file, for it to write via file stream. From my investigation into the OpenPyXL source code, it doesn't look like it supports this kind of output.…
Nelson Shaw
  • 913
  • 2
  • 9
  • 10
29
votes
3 answers

How to create directories automatically using ofstream

I am now writing an extractor for a basic virtual file system archive (without compression). My extractor is running into problems when it writes a file to a directory that does not exist. Extract function : void extract(ifstream * ifs, unsigned int…
Kacper Fałat
  • 593
  • 3
  • 7
  • 16
27
votes
2 answers

How can I make reverse scanning of a binary file faster?

I have a binary file specification that describes a packetized data structure. Each data packet has a two-byte sync pattern, so scanning for the beginning of a packet is possible, using a BinaryReader and FileStream…
Robert Harvey
  • 168,684
  • 43
  • 314
  • 475
27
votes
2 answers

Fastest way to read file length C#

I am using fs.Length, where fs is a FileStream. Is this an O(1) operation? I would think this would just read from the properties of the file, as opposed to going through the file to find when the seek position has reached the end. The file I am…
jpints14
  • 1,281
  • 6
  • 15
  • 24
27
votes
3 answers

How to open or launch PDF Files in C#.Net?

How do I launch a PDF Programmatically from a C# application in it's own process? Originally: I want to open PDF file when i click button in C#.Net?
Happy boy
  • 299
  • 1
  • 4
  • 4
26
votes
7 answers

Close a filestream without Flush()

Can I close a file stream without calling Flush (in C#)? I understood that Close and Dispose calls the Flush method first.
HelpME
  • 261
  • 1
  • 3
  • 4
25
votes
2 answers

Create and write to a text file inmemory and convert to byte array in one go

How can I create a .csv file implicitly/automatically by using the correct method, add text to that file existing in memory and then convert to in memory data to a byte array? string path = @"C:\test.txt"; File.WriteAllLines(path,…
HelloWorld
  • 4,100
  • 11
  • 38
  • 64
25
votes
3 answers

System.IO.FileStream FileAccess vs FileShare

I've searched all over but can't find an answer to this question. I understand that FileAccess deals with file access on the machine and FileShare deals with the share, but I can't find an explanation of how exactly it comes together and how they…
Storm
  • 1,298
  • 3
  • 11
  • 26
24
votes
3 answers

What's the difference between FileStream.Flush() and FileStream.Flush(True)?

MSDN says that FileStream.Flush(True) "also clears all intermediate file buffers.". What does "all intermediate file buffers" mean exactly?
cooldfish
  • 317
  • 1
  • 2
  • 5
23
votes
4 answers

Angular2 Displaying PDF

I have an angular2 project with an ASP.Net Web API. I have code to retrieve a file path from my database which goes to a document on my server. I then want to display this document in the browser in a new tab. Does anybody have any suggestions how…
DaRoGa
  • 1,848
  • 7
  • 29
  • 47
23
votes
7 answers

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…
Stefan Schultze
  • 8,590
  • 6
  • 31
  • 41