filestream

Handling with temporary file stream

怎甘沉沦 提交于 2019-11-30 14:41:24
Say I want to define a TempFileStream class that creates a temporary file using Path.GetTempFileName() method. A temporary file must be deleted when TempFileStream's object is no longer needed, e.g. closed or disposed: class TempFileStream: FileStream { string m_TempFileName = Path.GetTempFileName(); public TempFileStream(FileMode fileMode): base(m_TempFileName,fileMode) {} /// ... public ovverride Dispose(bool disposing) { /// ??? } } How should I implement this simply and safely? Try this one instead: public class TempFileStream : FileStream { public TempFileStream() : base(Path

Caching a binary file in C#

落花浮王杯 提交于 2019-11-30 14:16:29
Is it possible to cache a binary file in .NET and do normal file operations on cached file? The way to do this is to read the entire contents from the FileStream into a MemoryStream object, and then use this object for I/O later on. Both types inherit from Stream , so the usage will be effectively identical. Here's an example: private MemoryStream cachedStream; public void CacheFile(string fileName) { cachedStream = new MemoryStream(File.ReadAllBytes(fileName)); } So just call the CacheFile method once when you want to cache the given file, and then anywhere else in code use cachedStream for

SQL FileStream + Entity Framework store large files

允我心安 提交于 2019-11-30 13:21:54
问题 When i want to store a file in a filestream column, i always need to read the whole binary into the memory: using (MemoryStream memoryStream = new MemoryStream()) { sourceStream.CopyTo(memoryStream); binaryStore.Content = memoryStream.ToArray(); //Content = filestream column } is there a way with the entity framework, to put the stream directly? Because, if i want to upload a large file, i get a OutOfMemoryException. 回答1: Didn't see any update about FILESTREAM support in EF. ( Mentioned

Return Stream from WCF service, using SqlFileStream

不想你离开。 提交于 2019-11-30 08:34:45
I have a WCF service, from which users can request large datafiles (stored in an SQL database with FileStream enabled). These files should be streamed, and not loaded into memory before sending them off. So I have the following method that should return a stream, which is called by the WCF service, so that it can return the Stream to the client. public static Stream GetData(string tableName, string columnName, string primaryKeyName, Guid primaryKey) { string sqlQuery = String.Format( "SELECT {0}.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM {1} WHERE {2} = @primaryKey", columnName,

django return file over HttpResponse - file is not served correctly

无人久伴 提交于 2019-11-30 08:29:54
I want to return some files in a HttpResponse and I'm using the following function. The file that is returned always has a filesize of 1kb and I do not know why. I can open the file, but it seems that it is not served correctly. Thus I wanted to know how one can return files with django/python over a HttpResponse. @login_required def serve_upload_files(request, file_url): import os.path import mimetypes mimetypes.init() try: file_path = settings.UPLOAD_LOCATION + '/' + file_url fsock = open(file_path,"r") #file = fsock.read() #fsock = open(file_path,"r").read() file_name = os.path.basename

When using FileStream.ReadAsync() should I open the file in async mode?

人走茶凉 提交于 2019-11-30 07:56:53
问题 The old .Net way of performing asynchronous I/O for a FileStream is to use FileStream.BeginRead() and FileStream.EndRead(). The MSDN documentation for FileStream.BeginRead() states: FileStream provides two different modes of operation: synchronous I/O and asynchronous I/O. While either can be used, the underlying operating system resources might allow access in only one of these modes. By default, FileStream opens the operating system handle synchronously. In Windows, this slows down

SQL FileStream + Entity Framework store large files

落爺英雄遲暮 提交于 2019-11-30 07:08:33
When i want to store a file in a filestream column, i always need to read the whole binary into the memory: using (MemoryStream memoryStream = new MemoryStream()) { sourceStream.CopyTo(memoryStream); binaryStore.Content = memoryStream.ToArray(); //Content = filestream column } is there a way with the entity framework, to put the stream directly? Because, if i want to upload a large file, i get a OutOfMemoryException. Didn't see any update about FILESTREAM support in EF. ( Mentioned before as partial support with .net 3.5 sp1 release here ). I suppose entity framework is accessing FILESTREAM

Reusing a filestream

限于喜欢 提交于 2019-11-30 06:37:52
In the past I've always used a FileStream object to write or rewrite an entire file after which I would immediately close the stream. However, now I'm working on a program in which I want to keep a FileStream open in order to allow the user to retain access to the file while they are working in between saves. ( See my previous question ). I'm using XmlSerializer to serialize my classes to a from and XML file. But now I'm keeping the FileStream open to be used to save (reserialized) my class instance later. Are there any special considerations I need to make if I'm reusing the same File Stream

difference between memory stream and filestream

此生再无相见时 提交于 2019-11-30 06:18:55
问题 During the serialization we can use either memory stream or file stream. What is the basic difference between these two? What does memory stream mean? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary; namespace Serilization { class Program { static void Main(string[] args) { MemoryStream aStream = new MemoryStream(); BinaryFormatter aBinaryFormat = new BinaryFormatter(); aBinaryFormat.Serialize(aStream,

Sending File in Chunks to HttpHandler

假如想象 提交于 2019-11-30 05:43:33
问题 I'm trying to send a file in chunks to an HttpHandler but when I receive the request in the HttpContext, the inputStream is empty. So a: while sending I'm not sure if my HttpWebRequest is valid and b: while receiving I'm not sure how to retrieve the stream in the HttpContext Any help greatly appreciated! This how I make my request from client code: private void Post(byte[] bytes) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost:2977/Upload"); req.Method = "POST";