filestream

FileStream can't access the file because it's being used by another process

◇◆丶佛笑我妖孽 提交于 2019-12-20 02:11:33
问题 I'm new at web app in ASP.NET and I came across this problem. I have a page whe there is a Button to download a template.xls that is previously stored at a SharePoint page. I have the download method and it's working just fine. The template in question is being saved where it should be, on a folder where my web app is located, on my local IIS. The problem is to open this file to the end user. I need a popup to be displayed to the user, so he can open/save this template.xls I'm using the

How to handle concurrent file access with a filestream/streamwriter?

情到浓时终转凉″ 提交于 2019-12-19 08:57:02
问题 I am writing an audit file that is writing the username, time, and the old/changed values of several variables in the application for each user when they use my application. It is using a FileStream and StreamWriter to access the audit file. All audits for each user will be written to the same file. The issue is that when two users are updating this audit file at the same time, the "old value" of each of the variable is mixing up between the users. Why is this and how can you solve the

Can using FileShare.Delete cause a UnauthorizedAccessException?

浪尽此生 提交于 2019-12-19 06:04:34
问题 I'm opening a file with for reading that I had previously created in the user's %TEMP% folder, using the following code: new FileStream(cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete); On some user's computers, this sometimes throws an UnauthorizedAccessException with the message "Access to path ... is denied". I haven't been able to reproduce this. My initial guess is that an anti-virus or indexing engine is doing something funky, but I also noticed this

Can using FileShare.Delete cause a UnauthorizedAccessException?

那年仲夏 提交于 2019-12-19 06:04:08
问题 I'm opening a file with for reading that I had previously created in the user's %TEMP% folder, using the following code: new FileStream(cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete); On some user's computers, this sometimes throws an UnauthorizedAccessException with the message "Access to path ... is denied". I haven't been able to reproduce this. My initial guess is that an anti-virus or indexing engine is doing something funky, but I also noticed this

how do I zip multiple files using GZipStream in c#

吃可爱长大的小学妹 提交于 2019-12-18 17:54:19
问题 I have created multiple csv files using datatable and want to zip all those file into one single zip file. Which is i'm doing all at dynamically. I tried following code List<string> filestream = GenerateCSVfiles(dataSets); //Generate CSV files public List<string> GenerateCSVfiles(List<DataSet> dataSets) { List<string> filestream = new List<string>(); StringBuilder result = null; foreach (DataSet dataSet in dataSets) { result = new StringBuilder(); System.Data.DataTable dataTable = dataSet

FileStream.BeginWrite advantages over FileStream.Write?

痞子三分冷 提交于 2019-12-18 16:59:13
问题 I need to make a batch of writes to the same file but at different places within the file. I want to achieve this with the best performance possible and so have looked at the synchronous FileStream.Write and asynchronous FileStream.BeginWrite methods. A synchronous implemention is trivial and simply calls the FileStream.Write the required number of times in a loop. The async version calls FileStream.BeginWrite in a loop and then does a WaitHandle.WaitAll in order to block until they have all

Reusing a filestream

只谈情不闲聊 提交于 2019-12-18 12:20:23
问题 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

FileStream vs/differences StreamWriter?

假装没事ソ 提交于 2019-12-18 10:01:28
问题 Question: What is different between FileStream and StreamWriter in .Net ? What context are you supposed to use it? What is their advantage and disadvantage? Is it possible to combine these two into one? 回答1: What is different between FileStream and StreamWriter in dotnet? A FileStream is a Stream . Like all Streams it only deals with byte[] data. A StreamWriter : TextWriter , is a Stream-decorator. A TextWriter encodes Text data like string or char to byte[] and then writes it to the linked

Why does Code Analysis tell me, “Do not dispose objects multiple times” here:

[亡魂溺海] 提交于 2019-12-18 09:09:22
问题 On this code: public static string Base64FromFileName(string fileName) { try { FileInfo fInfo = new FileInfo(fileName); long numBytes = fInfo.Length; FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); byte[] bdata = br.ReadBytes((int)numBytes); br.Close(); fStream.Close(); return Convert.ToBase64String(bdata); } catch(Exception e) { throw e; } } ...I get, courtesy of Visual Studio's Code Analysis tool, the warning, " Do

Python read stream

故事扮演 提交于 2019-12-18 05:37:26
问题 I need a very inexpensive way of reading a buffer with no terminating string (a stream) in Python. This is what I have, but it wastes a a lot of CPU time and effort. Because it is constantly "trying and catching." I really need a new approach. Here is a reduced working version of my code: #! /usr/bin/env/ python import fcntl, os, sys if __name__ == "__main__": f = open("/dev/urandom", "r") fd = f.fileno() fl = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)