filestream

Runtime error Attempting to deserialize an empty stream

依然范特西╮ 提交于 2019-12-14 03:02:54
问题 I am trying to deserialize an list of string from a file. Here my code FileStream filestream = new FileStream(@"D:\cache.bin", FileMode.OpenOrCreate); try { BinaryFormatter binformat = new BinaryFormatter(); _cacheFileList = (List<string>)binformat.Deserialize(filestream); } catch (SerializationException ex) { Console.WriteLine(ex.Message); } finally { filestream.Close(); } I am getting a Runtime error. Attempting to deserialize an empty stream. 回答1: If you want support for empty files, first

Create 2 FileStream on the same file in the same process

泄露秘密 提交于 2019-12-14 00:50:35
问题 I'm trying to create a temporary file that will be automatically deleted. stream = new FileStream( tmpFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, FileOptions.DeleteOnClose|FileOptions.RandomAccess ); This file will be used by a 3rd party API which will also create a FileStream: stream = new FileStream( tmpFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); I think I've tried all possible combination of flags but I always get a "The process cannot

Add filename and length parameter to WCF stream when Transfermode = Stream

青春壹個敷衍的年華 提交于 2019-12-13 17:09:03
问题 In contrast to all the SO posts that talk about this topic, I'm not interested in wrapping a stream object in a [MessageContract] , since that is not permitted when in streaming mode (afaik). When I'm in streaming mode, how do I return to the client some metadata, such as length and filename? Can I add a WCF/SOAP header? How would I do this? I am looking into extending the filestream class and add a [MessageHeader] attribute, but I'm unable to get this to work. 回答1: here is how we do it

Uploading File To Azure Storage causes the error: Timeouts are not supported on this stream

柔情痞子 提交于 2019-12-13 16:21:58
问题 I have a form including a file upload to Azure Storage. This is where ToStream() method called: Image img= Image.FromStream(file.InputStream, true, true); if (img.Height != height || img.Width != width) img= img.GetThumbnailImage(width, height, null, new IntPtr()); img.ToStream().SaveAsBlob(blobname, filename); And this is ToStream() Method: public static Stream ToStream(this Image image) { Stream ms = new MemoryStream(); image.Save(ms, ImageFormat.Jpeg); ms.Position = 0; return ms; } Where I

FileStream.copyTo(Net.ConnectStream) what happens intern?

对着背影说爱祢 提交于 2019-12-13 15:31:28
问题 this code works fine. My question is what happens within the Net.ConnectionStream when i use the CopyTo() method? System.Net.HttpWebRequest request using (FileStream fileStream = new FileStream("C:\\myfile.txt") { using (Stream str = request.GetRequestStream()) { fileStream.CopyTo(str); } } More specific: What happens to the data? 1. write into the memory and upload then? (what's with big files?) 2. write into the network directly? (how does that work?) Thanks for your answers 回答1: It creates

C# add text to text file without rewriting it?

前提是你 提交于 2019-12-13 14:14:18
问题 Let's say I have the following code: StreamWriter sw = new StreamWriter(File.OpenWrite(Path)); sw.Write("Some stuff here"); sw.Dispose(); This code replaces the contents of the file with "Some stuff here," however I would like to add text to the file rather than replacing the text. How would I do this? 回答1: You need to tell the StreamWriter you want to append: var sw = new StreamWriter(path, true); File.OpenWrite doesn't support appending. 回答2: You could use the File.AppendAllText method and

Accessing Sql FILESTREAM from within a CLR stored procedure

被刻印的时光 ゝ 提交于 2019-12-13 14:13:48
问题 I'm trying to access a Sql filestream from a CLR stored procedure. I've set up a very simple database with a single table which includes a filestream column. I can successfully read from the filestream using a simple console app. Here's some example code for the proc that fails: [SqlProcedure] public static void GetDataFromFileStream(string path, out int data) { using (var connection = new SqlConnection("context connection=true")) { connection.Open(); var transaction = connection

Read large files

萝らか妹 提交于 2019-12-13 09:28:19
问题 I tried to read a 2+ gb file in two ways, the first: var file = File.ReadAllBytes(filepath); returns an exception, file over 2gb. Second way: var file = ReadAllBytes(filepath); public byte[] ReadAllBytes(string fileName) { byte[] buffer = null; using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); } return buffer; } Exception: "Array dimensions exceeded supported range." My goal is to send the file

OrmLite With Filestream

爷,独闯天下 提交于 2019-12-13 06:04:51
问题 I did some searching and I could not find very much on utilizing filestream with OrmLite. I think it is possible but I am not sure which direction to take. Ideally I would like to be able to create or drop/create a table based on a model with a binary field and then do something to make that column in the database mapped to the filestream. I know that the filestream has to be setup on sql server ahead of time (I don't think you can do ALL the filestream setup from outside of the Management

Flex/AIR/Actionscript/Mobile File.writeObject/readObject always generates null w/no errors generated

China☆狼群 提交于 2019-12-13 04:27:12
问题 I've been trying for several days just to get a simple writeObject/readObject functionality in my project. No matter what I do, the result is, a) a file is created and b) when I try to read that file back in, it is null . My project targets iOS on an iPad device, but this stripped down version targets the AIR simulator for an iPad. I've previously had every single available event registered and traced, but they never accomplished anything so I removed them for the sake of keeping the problem