filestream

UnauthorizedAccessException on creating file after deletion using FileStream

半城伤御伤魂 提交于 2019-12-04 20:57:39
I am facing an issue on client system. On trying to reproduce it in a sample code I have reproduced it. Here's the sample code Imports System.IO Public Class Form1 Private _lock As New Object Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As New Threading.Thread(AddressOf createFile) With t .IsBackground = True .Name = Guid.NewGuid.ToString .Start() End With End Sub Private Sub createFile() Dim path As String = "D:\SomeFile.txt" For i As Integer = 0 To 1000 SyncLock _lock If File.Exists(path) Then File.Delete(path) Using fs As

How to read byte blocks into struct

拜拜、爱过 提交于 2019-12-04 18:32:45
I have this resource file which I need to process, wich packs a set of files. First, the resource file lists all the files contained within, plus some other data, such as in this struct: struct FileEntry{ byte Value1; char Filename[12]; byte Value2; byte FileOffset[3]; float whatever; } So I would need to read blocks exactly this size. I am using the Read function from FileStream, but how can I specify the size of the struct? I used: int sizeToRead = Marshal.SizeOf(typeof(Header)); and then pass this value to Read, but then I can only read a set of byte[] which I do not know how to convert

C++: Read .txt contents and store into 2D array

穿精又带淫゛_ 提交于 2019-12-04 17:24:52
So me and my groupmates suddenly have some clutchwork at hand. I was assigned of making an import function that reads through a textfile that looks like this, and store it to a 2D array: The columns are Tab-separated. As this suddenly came up, dont have the entire project file with me and I am nowhere near my old reliables, I tried conjuring this up in the most generic way possible: void signal::import_data(string filename){ ifstream file; file.open(filename.c_str()); if(file.fail()){ cerr << "file open fail" << endl; }else{ while(!file.eof) { for(int j = 0; j < NumCols; j++){ for(int i = 0; i

SQL Server Filestream - Delete “speed”

笑着哭i 提交于 2019-12-04 12:01:40
问题 I'm working with the filestream datatype for the first time (SQL Server 2008) and I'm running into issues when I am doing some fast insert/deletes. Basically the speed at which the files are actually removed from the FileSystem is way slower then the insert/delete speed even if I invoke the garbage collector manually (As far as I know the CHECKPOINT is supposed to invoke the garbage collector). The code below illustrate the problem - It takes roughly 30 seconds to executes, but you have to

how to force send_data to download the file in the browser?

余生颓废 提交于 2019-12-04 11:19:48
Well my problem is that I'm using send_data on my Rails 3 application to send to the user a file from AWS S3 service with something like Base.establish_connection!( :access_key_id => 'my_key', :secret_access_key => 'my_super_secret_key') s3File = S3Object.find dir+filename, "my_unique_bucket" send_data(open(s3File.url).read,:filename=>filename, :disposition => 'attachment') but seems like the browser is buffering the file and before buffering it sends the file to download taking no time on the download but at the buffering time it's taking as long as the file size .... but what i need is the

How to create SHA256 hash of downloaded text file

泄露秘密 提交于 2019-12-04 09:42:44
I have a project where I get the url to a file (e.g. www.documents.com/docName.txt) and I want to create a hash for that file. How can I do this. FileStream filestream; SHA256 mySHA256 = SHA256Managed.Create(); filestream = new FileStream(docUrl, FileMode.Open); filestream.Position = 0; byte[] hashValue = mySHA256.ComputeHash(filestream); Label2.Text = BitConverter.ToString(hashValue).Replace("-", String.Empty); filestream.Close(); This is the code i have to create a hash. But seeing how it uses filestream it uses files stored on the hard drive (e.g. c:/documents/docName.txt) But i need it to

How to upload/update file by FileStream and ResumableUploader in C#

牧云@^-^@ 提交于 2019-12-04 06:34:32
问题 I wanna upload/update file by System.IO.FileStream in Google Documents List API(C#)? I use two way below: Google.GData.Client.ResumableUpload.ResumableUploader (1) public void UpdateAsync(Authenticator authentication, AbstractEntry payload, object userData) (2) public void UpdateAsync(Authenticator authentication, Uri resumableUploadUri, Stream payload, string contentType, object userData) (1) Success. (2) Failed with 403 Forbidden or another... So, does someone have any sample code about (2)

ASP.NET C# - Save FileStream on server

大兔子大兔子 提交于 2019-12-04 06:04:27
问题 I got beginners question. How to save a file stream to a file on server?! I got this: var source = Request.QueryString["src"]; WebClient webclient = new WebClient(); using (Stream stream = webclient.OpenRead(source)) { Bitmap iconbitmap = new Bitmap(System.Drawing.Image.FromStream(stream)); FileStream os = new FileStream("./asdasdasd.ico", FileMode.Create); var ic = MakeIcon(iconbitmap, 16, false); /// function returns an icon ic.Save(os); } My problem is than when I run code in ASP.NET

Flushing log to disk, exception in VerifyOSHandlePosition

允我心安 提交于 2019-12-04 05:30:40
问题 How can I write a logfile from a C# service so that it gets flushed to disk in a timely fashion? Here's what I've tried. In logging code, I opened a file like this: var file = return File.Open(name, FileMode.Append, FileAccess.Write, FileShare.Read); var writer = new StreamWriter(file); and wrote to it like this: writer.WriteLine(msg); writer.Flush(); file.Flush(); However the log was not flushed to disk in a timely fashion. So I tried adding a 5-second timer that does this: [DllImport(

How to Lock a file and avoid readings while it's writing

两盒软妹~` 提交于 2019-12-04 03:26:32
My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return the file while other thread is creating it. Also, I don't want to get a lock over a element that is common for all the files. Therefore I should lock the file just when I'm creating it. So I want to lock a file till its recreation is complete, if other thread