Working with Files and Streams in C#
Understanding file and data manipulation is key to a full understanding of C#. This course will teach you how to manage files and directories, read and write data in a number of different ways, and write unit tests using a mock file system.
What you'll learn
At the core of C# file IO is a thorough knowledge of how to manipulate files and directories and use streams. In this course, Working with Files and Streams in C#, you will learn the skills you need to read and write text, binary, and CSV files, and work with streams of data. First, you will learn how to manipulate files and directories on disk. Next, you will discover how to respond to changes in the file system and read and write data by loading entire files into memory or by incrementally processing them with streams. Finally, you will explore how to write testable file IO code and how to use a mock file system to create faster-executing and more maintainable tests. When you’re finished with this course, you will have a foundational understanding of file access and stream manipulation code that will help you immensely as you move forward and create your own file- or stream-manipulating applications.
Table of contents
- Introduction 2m
- Creating a New Console App 5m
- Checking if a File Exists 2m
- Getting the Parent Directory of a Path 3m
- Checking if a Directory Exists and Creating New Directories 4m
- Copying a File 2m
- Moving a File 2m
- Getting the File Extension from a File Name 5m
- Deleting a Directory 2m
- Enumerating All the Files in a Directory 3m
- Summary 1m
- Introduction 2m
- Introducing the FileSystemWatcher Class 2m
- The InternalBufferSize Property 2m
- Configuring Notification Filters 1m
- Additional Properties 1m
- Refactoring to Use a FileSystemWatcher 5m
- Observing the FileSystemWatcher Events 4m
- Automatically Processing Files 5m
- Ignoring Duplicate FileSystemWatcher Events with a ConcurrentDictionary 4m
- Ignoring Duplicate FileSystemWatcher Events with a MemoryCache 6m
- Adding Existing File Processing 1m
- FileSystemWatcher Testing Considerations 2m
- Summary 1m
- 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 5m
- Simplifying StreamReader and StreamWriter Creation 3m
- Selectively Processing Part of Stream 2m
- Using Streams to Read and Write Binary Data 5m
- Using BinaryReader and BinaryWriter 5m
- Specifying Text Encodings 2m
- Using Streams to Append Data 1m
- Random FileStream Access 3m
- MemoryStream Overview 1m
- Summary 2m
- Introduction 1m
- An Overview of the CsvHelper Library 1m
- Reading CSV Data Dynamically 8m
- Ignoring Blank Lines 1m
- Configuring a Custom Delimiter 2m
- Configuring CSV File Headers 3m
- Reading Data into Entity Classes 2m
- Configuring Header Validation and Missing Field Actions 3m
- Configuring Custom Class Mapping 4m
- Creating Custom Type Converters 4m
- Writing CSV Files 4m
- Summary 2m
- 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 7m
- Adding a BinaryFileProcessor Test 2m
- Adding a CsvFileProcessor Test 3m
- Asserting Mock File Output with Approval Tests 4m
- Summary, Resources, and Further Learning 2m