How do I create a file AND any folders, if the folders don’t exist?

To summarize what has been commented in other answers: //path = @”C:\Temp\Bar\Foo\Test.txt”; Directory.CreateDirectory(Path.GetDirectoryName(path)); Directory.CreateDirectory will create the directories recursively and if the directory already exist it will return without an error. If there happened to be a file Foo at C:\Temp\Bar\Foo an exception will be thrown.

How to copy a file while it is being used by another process

An Example (note: I just combined two google results, you may have to fix minor errors ;)) The important part is the FileShare.ReadWrite when opening the FileStream. I use a similar code to open and read Excel documents while excel is still open and blocking the file. using (var inputFile = new FileStream( “oldFile.txt”, FileMode.Open, … Read more

File access error with FileSystemWatcher when multiple files are added to a directory

A typical problem of this approach is that the file is still being copied while the event is triggered. Obviously, you will get an exception because the file is locked during copying. An exception is especially likely on large files. As a workaround you could first copy the file and then rename it and listen … Read more

Local file access with JavaScript

If the user selects a file via <input type=”file”>, you can read and process that file using the File API. Reading or writing arbitrary files is not allowed by design. It’s a violation of the sandbox. From Wikipedia -> Javascript -> Security: JavaScript and the DOM provide the potential for malicious authors to deliver scripts … Read more

tech