filestream

FileStream and a FileSystemWatcher in C#, Weird Issue “process cannot access the file”

独自空忆成欢 提交于 2019-12-04 01:58:36
问题 I have this complicated code-base that is listening for FileCreated events on a certain folder. When the file is Created (which also includes moving a file to that folder), I want to read in that file and do something with it. It works for the first file, but throws an exception after for all other attempts. In Debug-mode (With VisualStudio) the error would be thrown, but if i just click "continue".. it would then work (without an error). I have posted simplified code, which demonstrates the

Redirect writes to a file to a stream C#

[亡魂溺海] 提交于 2019-12-03 22:36:11
问题 I wanted to ask if it is possible to redirect writes to a specific file, to a memory stream in my application so I can immediately read it. If it is possible please explain how to do so. Thanks. 回答1: Make sure your application works with Stream , and then you can use the MemoryStream concrete implementation to accomplish streaming without a file. 回答2: What you need is a stream which writes to a file as well as to another stream which you are watching - a stream splitter, commonly known in the

Use SQL INSERT to Create Directories with FileTable

非 Y 不嫁゛ 提交于 2019-12-03 16:43:53
Is there a way to create directories in a FileTable without using File I/O APIs? Is it just as simple as creating a SQL INSERT statement? This is my first experience with SQL Server 2012 and I'm not familiar with the limits of the FileTable from within SQL Server. The following worked for me. Hopefully this helps out someone else. INSERT INTO FileTable0 (name,is_directory,is_archive) VALUES ('Directory', 1, 0); You should also check out Bob Beauchemin's Techdays 2012 video for more details on FileStream and its evolution into FileTable . 来源: https://stackoverflow.com/questions/10483906/use-sql

Can't delete temporary files after returning FileStream

别来无恙 提交于 2019-12-03 14:11:45
I have a function in a C# MVC application that creates a temporary directory and a temporary file, then opens the file using FileStream, returns the FileStream to a calling function, and then needs to delete the temporary files. However, I do not know how to delete the temp directory and file because it always errors out saying "the process cannot access the file because it is being used by another process." This is what I tried, but the FileStream is still using the temp file in the finally block. How can I return the FileStream and delete the temporary files? public FileStream

How to force the filestream garbage collector to complete its work with the highest priority?

左心房为你撑大大i 提交于 2019-12-03 13:36:31
问题 After asking this question it is clear to me that I need to be able to perform the garbage collection in the fastest possible time. How is it possible to tell SQL Server filestream's garbage collector to delete all the files with high priority? I tried with the CHECKPOINT statement, even by setting a duration (CHECKPOINT 100), but nothing changes. After deleting 40000 filestream records I see that the garbage collector removes 4-5 files per second. How to tell him "delete them all now"? 回答1:

Looping through lines of txt file uploaded via FileUpload control

青春壹個敷衍的年華 提交于 2019-12-03 13:22:56
I want to select a simple .txt file that contains lines of strings using a FileUpload control. But instead of actually saving the file I want to loop through each line of text and display each line in a ListBox control. Example of a text file: test.txt 123jhg345 182bdh774 473ypo433 129iiu454 What is the best way to accomplish this? What I have so far: private void populateListBox() { FileUpload fu = FileUpload1; if (fu.HasFile) { //Loop trough txt file and add lines to ListBox1 } } 62071072SP private void populateListBox() { FileUpload fu = FileUpload1; if (fu.HasFile) { StreamReader reader =

FileStream not closing file

北战南征 提交于 2019-12-03 12:43:27
I have the following code: using (MemoryStream str = new MemoryStream()) { Program.api.GetDocument(result, str); using (FileStream fileStream = File.Create(filePath)) { str.WriteTo(fileStream); } } Whenever a file is written, it is always locked afterwards - attempting to delete it or modify it causes Windows to tell me the file is in use, even after closing my application. Am I missing something? Your problem is most likely caused by Windows Search Indexing which is a part of Windows Search . If you attempt to access the file immediately (or very shortly) after modifying it, you may run into

How to create directories automatically using ofstream [duplicate]

女生的网名这么多〃 提交于 2019-12-03 10:45:34
问题 This question already has answers here : How can I create directory tree in C++/Linux? (15 answers) Closed 3 years ago . 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 offset, unsigned int length, std::string path) { char * file = new char[length]; ifs->seekg(offset); ifs->read(file, length);

Can Stream.CopyTo() method save the streams incomplete?

送分小仙女□ 提交于 2019-12-03 08:51:41
I have a WCF service which allows me to upload files in chunks. What I am wondering is could this code can cause the uploaded stream to be only partially appended to the target stream in any case? I have my logs that shows me that all the sent streams are 512000 byte(which I set on client side) and I've sent 6 chunks out of 9 chunks so far. But on server the files size is 2634325. Which means the last chunk sent(6th) is saved incompletely. What can be causing this behaviour? What should I do to avoid this? Or is this completely safe, and I should look for the bug in somewhere else? public void

VB - How do I read and write a binary file?

一个人想着一个人 提交于 2019-12-03 07:52:29
How do I read a raw byte array from any file... Dim bytes() as Byte ..and then write that byte array back into a new file? I need it as a byte array to do some processing in between. I'm currently using: To read Dim fInfo As New FileInfo(dataPath) Dim numBytes As Long = fInfo.Length Dim fsAs New FileStream(dataPath, FileMode.Open, FileAccess.Read) Dim br As New BinaryReader(fs) Dim bytes As Byte() = br.ReadBytes(CInt(numBytes)) br.Close() fs.Close() To write Dim fs As System.IO.FileStream fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create) fs.Write(bytes, 0, bytes.Length) fs