filestream

SQL Server FILESTREAM limitation

早过忘川 提交于 2019-11-27 14:50:44
问题 I am looking at FILESTREAM attribute in SQL Server to store files in it. I understand it stores the files on hard drive and stores the file pointer/path information in DB. Also, maintains transactional consistency in the process. There also seems to be a limitation "FILESTREAM data can be stored only on local disk volumes" for the FILESTREAM attribute. If i anticipate my web app to store 200,000 images of 1-2mb each, i would require around 200gb of hard drive space to store the images. Since,

Convert a Stream to a FileStream in C#

天大地大妈咪最大 提交于 2019-11-27 14:49:59
问题 What is the best method to convert a Stream to a FileStream using C#. The function I am working on has a Stream passed to it containing uploaded data, and I need to be able to perform stream.Read(), stream.Seek() methods which are methods of the FileStream type. A simple cast does not work, so I'm asking here for help. 回答1: Read and Seek are methods on the Stream type, not just FileStream . It's just that not every stream supports them. (Personally I prefer using the Position property over

File.ReadLines without locking it?

我怕爱的太早我们不能终老 提交于 2019-11-27 14:42:13
I can open a FileStream with new FileStream(logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Without locking the file. I can do the same with File.ReadLines(string path) ? xanatos No... If you look with Reflector you'll see that in the end File.ReadLines opens a FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.SequentialScan); So Read-only share. (it technically opens a StreamReader with the FileStream as described above) I'll add that it seems to be child's play to make a static method to do it: public static IEnumerable<string> ReadLines

C# Download big file from Server with less memory consumption

让人想犯罪 __ 提交于 2019-11-27 13:20:28
问题 I have a big file of memory size 42 mb. I want to download the file with less memory consumption. Controller Code public ActionResult Download() { var filePath = "file path in server"; FileInfo file = new FileInfo(filePath); Response.ContentType = "application/zip"; Response.AppendHeader("Content-Disposition", "attachment; filename=folder.zip"); Response.TransmitFile(file.FullName); Response.End(); } alernative method tried with Stream public ActionResult Download() { string failure = string

System.IO.FileStream FileAccess vs FileShare

孤街醉人 提交于 2019-11-27 12:45:25
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 impact one another. For example, if I have using ( FileStream fs = new FileStream( pathName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) does that mean that users on the machine can only read the file whilst users remotely accessing the folder can read and write to the file? Additionally, what would the impact be in using using ( FileStream

How to fgets() a specific line from a file in C?

眉间皱痕 提交于 2019-11-27 09:32:11
So, I'm trying to find a way to fgets() a specific line in a text file in C, to copy the contents of the line into a more permanent buffer: Essentially, I was wondering if there was a way to do that without something similar to the following code: FILE *fp; fp = fopen(filename, "r"); char line[256]; char * buffer; int targetline = 10; while( targetline > 0) { fgets(line, 256, fp) } buffer =(char*)malloc(sizeof(char) * strlen(line)); strcpy(buffer, line); So basically I don't want to iterate through the file n-1 times just to get to the nth line... it just doesn't seem very efficient (and, this

Read excel file from a stream

别说谁变了你拦得住时间么 提交于 2019-11-27 09:14:09
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 either. So, anyone know of a way to read a Excel file from a FileUpload stream? It seems i found a soultion to the problem myself. http://www.codeplex.com/ExcelDataReader This library seems to work nicely and it takes a stream to read the excel file. ExcelDataReader

Copy MemoryStream to FileStream and save the file?

折月煮酒 提交于 2019-11-27 08:12:51
I don't understand what I'm doing wrong here. I generate couple of memory streams and in debug-mode I see that they are populated. But when I try to copy MemoryStream to FileStream in order to save the file fileStream is not populated and file is 0bytes long (empty). Here is my code if (file.ContentLength > 0) { var bytes = ImageUploader.FilestreamToBytes(file); // bytes is populated using (var inStream = new MemoryStream(bytes)) // inStream is populated { using (var outStream = new MemoryStream()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(inStream) .Resize(new Size

Need help understanding Stream.Read()

只愿长相守 提交于 2019-11-27 08:11:45
问题 I am a little confused as to the steps of reading a file into buffer gradually. from the MSDN docs public abstract int Read( byte[] buffer, int offset, int count ) source from C# Examples FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); try { int length = (int)fileStream.Length; // get file length buffer = new byte[length]; // create buffer int count; // actual number of bytes read int sum = 0; // total number of bytes read // read until Read method returns 0

OutOfMemoryException when send big file 500MB using FileStream ASPNET

和自甴很熟 提交于 2019-11-27 07:43:09
I'm using Filestream for read big file (> 500 MB) and I get the OutOfMemoryException. I use Asp.net , .net 3.5, win2003, iis 6.0 I want this in my app: Read DATA from Oracle Uncompress file using FileStream and BZip2 Read file uncompressed and send it to asp.net page for download. When I read file from disk, Fails !!! and get OutOfMemory... . My Code is: using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { byte[] b2 = ReadFully(fs3, 1024); } // http://www.yoda.arachsys.com/csharp/readbinary.html public static byte[] ReadFully(Stream stream, int initialLength) { // If