Working with Files in C# 10
Reading and writing data to streams and files is central to many .NET applications, but it can be confusing. This course will teach you how to perform essential file operations and read and write text, binary, and CSV data to streams and files.
What you'll learn
Reading and writing data is central to many .NET applications, but it can be difficult to know which approach to take. In this course, Working with Files in C# 10, you’ll gain the ability to read and write data and manage files. First, you’ll explore how to manage files and directories stored on disk. Next, you’ll discover how to monitor and respond to changes in the file system. Finally, you’ll learn how to read, process, and write data in text, binary, and CSV formats. When you’re finished with this course, you’ll have the skills and knowledge of C# files and streams needed to read, write, and process data in your C# applications.
Table of contents
- Introduction 2m
- Creating a New Console App 7m
- Checking if a File Exists 4m
- Getting the Parent Directory of a Path 3m
- Checking if a Directory Exists and Creating New Directories 4m
- Copying a File 3m
- Moving a File 4m
- Getting the File Extension from a File Name 3m
- Checkpoint 01 - Get the Parent Directory for a Path 0m
- Changing a Filename Extension 3m
- Checkpoint 02 - Get the Extension Part of a Filename 0m
- Deleting a Directory 3m
- Enumerating All the Files in a Directory 4m
- Summary 2m
- Exercise 01 - Copying and Deleting Files 0m
- Introduction 2m
- Introducing the FileSystemWatcher Class 2m
- The InternalBufferSize Property 2m
- Configuring Notification Filters 1m
- Additional Properties 1m
- Refactoring to Use a FileSystemWatcher 6m
- Checkpoint 03 - Define a New FileSystemWatcher Instance in Code 0m
- Observing the FileSystemWatcher Events 5m
- Automatically Processing Created Files 3m
- Automatically Processing Changed Files 3m
- Checkpoint 04 - Set a FileSystemWatcher to notify solely on file name changes 0m
- Ignoring Duplicate FileSystemWatcher Events with a ConcurrentDictionary 6m
- Ignoring Duplicate FileSystemWatcher Events with a MemoryCache 7m
- Adding Existing File Processing 1m
- FileSystemWatcher Testing Considerations 2m
- Summary 1m
- Introduction 2m
- Reading and Writing Text Files 6m
- Checkpoint 05 - Use the File class to read all the text from a file into a string 0m
- Reading and Writing Text Files with String Arrays 3m
- Checkpoint 06 - Use the File class to write a string instance to a text file 0m
- Specifying Text Encodings 4m
- Appending Text Content 1m
- Reading and Writing the Entire Contents of Binary Files 4m
- Checkpoint 07 - Use the File class to read binary data from a file into a byte array 0m
- Considerations 1m
- Summary 1m
- Exercise 03 - Write a simple app to read text from a text file, convert it to uppercase, and write it out to a new file 0m
- Introduction 2m
- An Introduction to Streams 3m
- The Benefits of Streams 1m
- .NET Class Hierarchy Overview 4m
- Using Streams to Read and Write Text Content 9m
- FileStreamOptions Properties 4m
- Simplifying StreamReader and StreamWriter Creation 2m
- Checkpoint 08 - Use a static method on the File class to define a StreamReader instance 0m
- Checkpoint 09 - Define a StreamWriter instance for a given file path 0m
- Selectively Processing Part of Stream 1m
- Using Streams to Read and Write Binary Data 4m
- Using BinaryReader and BinaryWriter 6m
- Checkpoint 10 - Define a FileStream instance using a static File method to read data 0m
- Specifying Text Encodings 1m
- Using Streams to Append Data 1m
- Random FileStream Access 3m
- MemoryStream Overview 1m
- Asynchronous Streams 3m
- Thread-safe File IO 3m
- Summary 2m
- Exercise 04 - Create a simple application to read binary data one byte at a time using a stream 0m
- Introduction 2m
- An Overview of the CsvHelper Library 1m
- Reading CSV Data Dynamically 6m
- Checkpoint 11 - Define a CsvConfiguration that uses an invariant culture 0m
- Checkpoint 12 - Use CsvHelper to read all the records in a CSV file as dynamic data 0m
- Configuring CSV Comment Reading 2m
- Configuring Trimming of Whitespace 1m
- Configuring CSV Blank Line Handling 1m
- Configuring CSV File Headers 2m
- Configuring a Custom Delimiter 2m
- Checkpoint 13 - Configure CsvHelper to use a semicolon instead of a comma 0m
- Reading CSV Data in a Strongly Typed Way 2m
- Configuring Custom Class Mapping 5m
- Creating Custom Type Converters 3m
- Configuring Header Validation and Missing Field Actions 3m
- Writing CSV Files 2m
- Summary 2m
- Exercise 05 - Create Strongly typed Classes 0m
- Introduction 1m
- The Problems with Testing File Access Code 2m
- An Overview of System.IO.Abstractions 2m
- Refactoring for Testability 7m
- Adding a TextFileProcessor Test 8m
- Checkpoint 14 - Create a MockFileData instance containing 3 lines of text 0m
- Adding a BinaryFileProcessor Test 3m
- Checkpoint 15 - Add a file to a MockFileSystem instance 0m
- Adding a CsvFileProcessor Test 3m
- Checkpoint 16 - Add a directory to a MockFileSystem instance 0m
- Checkpoint 17 - Read a file from a MockFileSystem instance 0m
- Asserting Mock File Output with Approval Tests 5m
- Summary, Resources, and Further Learning 2m
- Exercise 06 - Write a class that abstracts away the physical file system so that it can be unit tested 0m