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.

2765 questions
45
votes
11 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
  • 487
  • 1
  • 4
  • 10
41
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
  • 1,103
  • 2
  • 10
  • 10
37
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,662
  • 8
  • 42
  • 63
34
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
  • 27,829
  • 22
  • 107
  • 159
34
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
  • 343
  • 1
  • 3
  • 4
33
votes
5 answers

Http MultipartFormDataContent

I have been asked to do the following in C#: /** * 1. Create a MultipartPostMethod * 2. Construct the web URL to connect to the SDP Server * 3. Add the filename to be attached as a parameter to the MultipartPostMethod with parameter name…
user2985419
  • 553
  • 3
  • 9
  • 23
31
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,361
  • 6
  • 15
  • 24
31
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
  • 633
  • 3
  • 9
  • 17
29
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,671
  • 12
  • 46
  • 78
28
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
  • 309
  • 1
  • 4
  • 4
28
votes
4 answers

Read the actual contents of text file using FileStream and these options c#

I need to open a text file within C# using FileStream and with the options mentioned below var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, …
user1776480
  • 319
  • 1
  • 4
  • 5
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
  • 178,213
  • 47
  • 333
  • 501
27
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
  • 271
  • 1
  • 3
  • 4
27
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,848
  • 4
  • 20
  • 39
26
votes
1 answer

How do I load a string into a FileStream without going to disk?

string abc = "This is a string"; How do I load abc into a FileStream? FileStream input = new FileStream(.....);
Mennan
  • 4,451
  • 13
  • 54
  • 86