Questions tagged [system.io.file]

In C#, F#, VB and C++ provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.

In C#, F#, VB and C++ provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.

To browse the .NET Framework source code for this type, see the Reference Source.

See: https://learn.microsoft.com/en-us/dotnet/api/system.io.file

341 questions
42
votes
6 answers

Does the .net framework provides async methods for working with the file-system?

Does the .net framework has an async built-in library/assembly which allows to work with the file system (e.g. File.ReadAllBytes, File.WriteAllBytes)? Or do I have to write my own library using the async Methods of StreamReader and…
BendEg
  • 20,098
  • 17
  • 57
  • 131
29
votes
2 answers

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

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,…
HelloWorld
  • 4,671
  • 12
  • 46
  • 78
17
votes
2 answers

How to WriteAllLines in C# without CRLF

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…
jared
  • 1,344
  • 4
  • 20
  • 38
12
votes
3 answers

File.Copy(sourceFileName,destFileName,overwrite) does not work on some OS

I am seeing weird errors with the following code snippet: File.Copy(oldPath, targetPath,true); File.SetAttributes(targetPath, FileAttributes.Normal); A file has to be moved somewhere else, and because I lack write right at the source path, I copy…
DevilSuichiro
  • 1,049
  • 8
  • 21
9
votes
1 answer

Path does not exist in current context c# .net coding?

In my c# code when I used Path.GetExtension , It is showing "Path does not exist in current context". Seems libraries for Path does not exist in current application. But I searched and found Path class defined in System.IO and System.IO is by…
8
votes
2 answers

Read text file with IAsyncEnumerable

I came across IAsyncEnumerable while I am testing C# 8.0 features. I found remarkable examples from Anthony Chu (https://anthonychu.ca/post/async-streams-dotnet-core-3-iasyncenumerable/). It is async stream and replacement for…
phonemyatt
  • 1,287
  • 17
  • 35
7
votes
2 answers

Getting html file from path for an Azure Function

I have a html file that is an email template. In my Azure function I want to read the file in with 'HtmlDocument', manipulate it, then send it out as an email to members. How do I read the file 'hero.html' from my Azure Function app? And then once I…
chuckd
  • 13,460
  • 29
  • 152
  • 331
6
votes
1 answer

Make MAF AddInProcess.exe "Long Path Aware"

I'm trying to make my Addin's (using MAF) AddInProcess.exe (created by the AddInProcess class) "long path aware" for Windows 10. The difficulty stems from the fact that I don't own the AddInProcess.exe. It is part of the .NET Framework, and lives…
Matt Smith
  • 17,026
  • 7
  • 53
  • 103
6
votes
2 answers

What is the difference between DirectorySeparatorChar and AltDirectorySeparatorChar

System.io.DirectorySeparatorChar returns the character "\" while System.io.AltDirectorySeparatorChar returns "/" to be more specific what is the job of System.Io.AltDirectorySeparatorChar and when we use it?
Ahmed Ibrahim
  • 681
  • 8
  • 12
6
votes
1 answer

C# WriteAllBytes ignores character encoding

I'm using the following code: File.WriteAllBytes("c:\\test.xml", Encoding.UTF8.GetBytes("THIS IS A TEST")) Which should in theory write a UTF8 file, but I just get an ANSI file. I also tried this just to be especially…
Tony Cheetham
  • 877
  • 7
  • 18
6
votes
1 answer

Access to path is denied - File.Move fails but File.Delete works

I'm trying to perform a simple File.Move operation but I get System.UnauthorizedAccessException exception - Access to the path is denied. To my knowledge, nothing is using the file I am trying to move (containing folder is closed as well). I can…
Roka545
  • 3,404
  • 20
  • 62
  • 106
6
votes
2 answers

File.ReadAllBytes throws IOException saying the process can't access the file because it is being used by another process

Can File.ReadAllBytes cause IOException when it is called twice without enough interval between the calls? When I set Row and Col of grid, it fires RowColChange event. The RowColChange has some code which opens the same file by using…
Jyina
  • 2,530
  • 9
  • 42
  • 80
6
votes
1 answer

Copy file to Sharepoint-share fails unless user connects to Sharepoint server for the first time

I have a strange behaviour when I try to use a C# program to copy local files to a Sharepoint Server using UNC paths provided by Sharepoint to access the file system. First of all, my user has all the privileges required to access that specific…
Erik
  • 2,316
  • 9
  • 36
  • 58
5
votes
2 answers

Image.Save Parameter not valid

I want to watermark files in a folder with another image. However, am getting the error 'Parameter Not Valid' when invoking the code img.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg); I have the following code; public static string…
Matthew Flynn
  • 3,661
  • 7
  • 40
  • 98
5
votes
2 answers

Using IDisposable to Delete a File from Disk

I have a situation where I need to save an uploaded HttpPostedFile to the server's disk, provide its full path to some code that will do something with the file on disk, then delete the file. I decided to make a proxy for working with the file. …
bubbleking
  • 3,329
  • 3
  • 29
  • 49
1
2 3
22 23