system.io.file

Asynchronously copy large files while reporting progress to a progress bar (example?)

半腔热情 提交于 2020-04-22 05:15:29
问题 I need to copy a number of large files and report progress back to the UI via a progress bar. I bought "C# 5.0 in a Nutshell". I'm on page 597. I have been reading about parallel programming. I am trying to accomplish what in my mind is quite simple based on some examples in this book, but I'm really struggling. There must be some gaps in my understanding. This is why I'm posting this question. I have looked into background workers, but find myself running into cross-threading compiler errors

Xamarin Forms how to Save a file to a location where it can be copied off of the original device

戏子无情 提交于 2020-03-04 18:05:14
问题 My Xamarin forms app required the user to perform a certain amount of configuration before it can be used. Additionally, the app can be run on multiple computers by the same user (There are valid business reasons for doing this.) What I would like to be able to do is backup the configuration of the app to a file that can then be used on another device to automatically configure the app on the new device in exactly the same way. This will prevent the users from re-entering all the

Xamarin Forms how to Save a file to a location where it can be copied off of the original device

你离开我真会死。 提交于 2020-03-04 18:04:16
问题 My Xamarin forms app required the user to perform a certain amount of configuration before it can be used. Additionally, the app can be run on multiple computers by the same user (There are valid business reasons for doing this.) What I would like to be able to do is backup the configuration of the app to a file that can then be used on another device to automatically configure the app on the new device in exactly the same way. This will prevent the users from re-entering all the

Unable to delete some files via System.IO.File in C# console app

两盒软妹~` 提交于 2020-01-06 15:11:32
问题 I am encrypting some text files. It works fine the file is encypted, however on occasion I get this error when attempting to delete the original unencrypted file: System.IO.IOException: The process cannot access the file 'MyFile.TXT' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.Delete(String path) at FileEncryption.Program.DeleteFile(String sInputFilename) in FileEncryption\Program.cs:line 159 This seems

read a text file and search for string in memory efficient way (and abort when found)

社会主义新天地 提交于 2020-01-06 02:45:07
问题 I'm searching for a string in a text file (also includes XML). This is what I thought first: using (StreamReader sr = File.OpenText(fileName)) { string s = String.Empty; while ((s = sr.ReadLine()) != null) { if (s.Contains("mySpecialString")) return true; } } return false; I want to read line by line to minimize the amount of RAM used. When the string has been found it should abort the operation. The reason why I don't process it as XML is because it has to be parsed and would also consume

Create and write to a text file inmemory and convert to byte array in one go

非 Y 不嫁゛ 提交于 2019-12-22 01:56:25
问题 How can I create a .csv file implicitly/automatically by using the correct method, add text to that file existing in memory and then convert to in memory data to a byte array? string path = @"C:\test.txt"; File.WriteAllLines(path, GetLines()); byte[] bytes = System.IO.File.ReadAllBytes(path); With that approach I create a file always (good), write into it (good) then close it (bad) then open the file again from a path and read it from the hard disc (bad) How can I improve that? UPDATE One

How to WriteAllLines in C# without CRLF

大城市里の小女人 提交于 2019-12-17 19:38:43
问题 I'm using C# and am trying to output a few lines to an ASCII file. The issue I'm having is that my Linux host is seeing these files as: ASCII text, with CRLF line terminators I need this file to be just: ASCII text The CRLF is causing some issues and I was hoping there was a way in C# to just create the file formatted in the way I want. I'm basically using this code: string[] lines = { "Line1", "Line2" }; File.WriteAllLines(myOutputFile, lines, System.Text.Encoding.UTF8); Is there an easy way

The process cannot access the file because it is being used by another process

…衆ロ難τιáo~ 提交于 2019-12-13 02:13:45
问题 I am trying to do the following: var path = Server.MapPath("File.js")); // Create the file if it doesn't exist or if the application has been restarted // and the file was created before the application restarted if (!File.Exists(path) || ApplicationStartTime > File.GetLastWriteTimeUtc(path)) { var script = "..."; using (var sw = File.CreateText(path)) { sw.Write(script); } } However occasionally the following error is sometimes thrown: The process cannot access the file '...\File.js' because

error 502.5 and System.IO.FileNotFoundException

こ雲淡風輕ζ 提交于 2019-12-11 17:43:48
问题 When I try to navigate to my domainname that I set up with IIS (it's a core app) I get the error: HTTP Error 502.5 - Process Failure I then try to run it via the cmd to get an more ellaborate error message: C:\inetpub\wwwroot\algoritmtrading.se>mvcrepetition.dll Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file