{"id":50333058,"url":"https://github.com/kernix13/csharp-system-io-classes","last_synced_at":"2026-05-29T11:01:31.885Z","repository":{"id":356186095,"uuid":"1231419126","full_name":"Kernix13/csharp-system-io-classes","owner":"Kernix13","description":"A CSharp app that creates, deletes, reads, and writes to files using classes from the .NET System.IO namespace","archived":false,"fork":false,"pushed_at":"2026-05-07T00:31:00.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-07T02:29:37.840Z","etag":null,"topics":["csharp","file-management","json-parsing","learning-exercises","systemio"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kernix13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-07T00:16:01.000Z","updated_at":"2026-05-07T00:31:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Kernix13/csharp-system-io-classes","commit_stats":null,"previous_names":["kernix13/csharp-system-io-classes"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Kernix13/csharp-system-io-classes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kernix13%2Fcsharp-system-io-classes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kernix13%2Fcsharp-system-io-classes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kernix13%2Fcsharp-system-io-classes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kernix13%2Fcsharp-system-io-classes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kernix13","download_url":"https://codeload.github.com/Kernix13/csharp-system-io-classes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kernix13%2Fcsharp-system-io-classes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33648534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","file-management","json-parsing","learning-exercises","systemio"],"created_at":"2026-05-29T11:01:30.044Z","updated_at":"2026-05-29T11:01:31.877Z","avatar_url":"https://github.com/Kernix13.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSharp System.IO Classes\n\nThis is a CSharp app using `System.IO` app classes to manipulate files and directories. This app creates and deletes files, reads from files, writes to files, and parses data in files using the `Path`, `Directory`, and `File` classes.\n\nOther classes to add to this project:\n\n- FileStream\n- StreamReader\n- StreamWriter\n- BinaryReader\n- BinaryWriter\n- FileInfo\n\n\u003cspan aria-hidden=\"true\"\u003e\u003cbr\u003e\u003c/span\u003e\n\n## Installation \u0026 Usage\n\n1. Clone this repository and switch into project folder\n\n   ```sh\n   git clone https://github.com/Kernix13/csharp-system-io-classes.git SystemIOClasses\n   cd SystemIOClasses\n   ```\n\n2. Run the application\n\n   ```bash\n   dotnet run\n   ```\n\n3. Build the application\n\n   ```bash\n   dotnet build\n   ```\n\n### Quick Start\n\n```sh\ngit clone https://github.com/Kernix13/csharp-system-io-classes.git SystemIOClasses\ncd SystemIOClasses\ndotnet run\n```\n\n\u003cspan aria-hidden=\"true\"\u003e\u003cbr\u003e\u003c/span\u003e\n\n## Important notes and code\n\n### Files and folders\n\n1. The `System.IO` namespace\n2. The `Directory` class contained in the System.IO namespace\n   - static methods: creating, moving, \u0026 enumerating thru directories\n3. The `System.Collections.Generic`: a namespace in .NET that contains classes and interfaces for defining generic collections which allow you to create strongly typed groups of objects, such as lists and dictionaries, which offer better performance and type safety than non-generic collections\n   - You need to add it with a `using` statement for Lists and IEnumerable\n   - When you wrote `IEnumerable\u003cstring\u003e`, that angle-bracket syntax (`\u003cstring\u003e`) is called a Generic. It’s basically telling C#, \"I want a sequence, but specifically a sequence of strings.\" Without `System.Collections.Generic`, the computer wouldn't know how to handle that typed list.\n\n#### Classes\n\n- The `Directory` class: often used to list out (or enumerate) directories\n  - What is `IEnumerable`\n  - `EnumerateDirectories(\"dirName\")`: list the names of all of the folders in a directory\n  - `EnumerateFiles(\"dirName\")`: list the names of all of the files in a directory,\n  - `SearchOption.AllDirectories`:\n\n```cs\nusing System.IO;\n\n// Folders/directories\nIEnumerable\u003cstring\u003e listOfDirectories = Directory.EnumerateDirectories(\"stores\");\nforeach (var dir in listOfDirectories) {\n    // just outputs dir/foldername\n    Console.WriteLine(dir);\n}\n\n// Files\nIEnumerable\u003cstring\u003e files = Directory.EnumerateFiles(\"stores\");\nforeach (var file in files) {\n    // just outputs dir/filename.ext\n    Console.WriteLine(file);\n}\n\n// EnumerateDirectories('folder', \"pattern\", SearchOption.AllDirectories)\n// EnumerateFiles('folder', \"pattern\", SearchOption.AllDirectories)\n```\n\n### File paths\n\n.NET provides some built-in constants and utility functions to make it easier to handle file paths.\n\n1. `System.Environment`: A class that provides a static set of tools to retrieve information about and manipulate the current platform and execution environment\n   - `System.Environment.SpecialFolder`: enumeration specifies constants to retrieve paths to special system folders\n   - `System.Environment.SpecialFolder`: enumeration specifies constants to retrieve paths to special system folders, such as a home directory\n\n#### Classes\n\n- `Directory.GetCurrentDirectory()`: exposes the full path to the current directory - like `Path`, to define and compose file-system paths\n- `Path`: located in the System.IO namespace - builds \u0026 parses strings, it doesn't care whether things actually exist\n  - `Path.DirectorySeparatorChar` field: `\\` vs `/` for different OSs\n  - `Path.Combine(\"parent\", \"child\")`\n  - `Path.GetExtension(\"file.ext\")`: returns .ext\n- `DirectoryInfo(filename)`:\n- `FileInfo (filename)`:\n- What is `Environment.NewLine`? To put the value on its own line\n\n```cs\n// Determine the current directory\nConsole.WriteLine(Directory.GetCurrentDirectory());\n\n// return the path to the equivalent of the Windows Documents folder, or the user's HOME directory for any operating system\nstring docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);\n// this is functionally identical:\nstring path2 = Environment.GetFolderPath(Environment.SpecialFolder.Personal);\n\n// Use correct DirectorySeparatorChar\nConsole.WriteLine($\"dirName{Path.DirectorySeparatorChar}subFolderName\");\n\n// Path.Combine\nConsole.WriteLine(Path.Combine(\"stores\", \"201\")); // outputs: stores/201\n\n// Get file extension of a file\nConsole.WriteLine(Path.GetExtension(\"sales.json\")); // outputs: .json\nvar extension = Path.GetExtension(file);\n\n// FileInfo\nFileInfo info = new FileInfo(fileName);\n// info.FullName\n// info.Directory\n// info.Extension\n// info.CreationTime\n```\n\n### Create files and directories\n\n- `Directory` class: also can create, delete, copy, move, \u0026 manipulate directories\n  - `Directory.CreateDirectory()`: It creates any directories and subdirectories passed to it\n  - `Directory.Exists(filePath)`: checks if a directory already exists - returns a boolean\n- `File`: does the same as `Directory`\n  - `File.WriteAllText()`: takes in a path to the file and the data you want to write to the file. If the file already exists, it's overwritten\n\n```cs\n// Create a new folder called newDir inside the 201 folder\n// If /stores/201 doesn't already exist, it's created automatically\nDirectory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), \"stores\",\"201\",\"newDir\"));\nstring currDir = Directory.GetCurrentDirectory();\nDirectory.CreateDirectory(Path.Combine(currDir, \"data\"));\n\n// Make sure directories exist\nbool doesDirectoryExist = Directory.Exists(filePath);\n\nstring sep = Path.DirectorySeparatorChar;\nbool doesDirectoryExist = Directory.Exists($\"{currDir}{sep}data\");\nConsole.WriteLine(doesDirectoryExist);\n\n// Create a file\nFile.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), \"greeting.txt\"), \"Hello World!\");\n\nFile.WriteAllText(Path.Combine(currDir, \"text.txt), \"Testing File.WriteAllText\"));\n```\n\n### Read and write to files\n\n- `File`: does the same as `Directory`\n  - `File.ReadAllText()`: Used to read files - The return object is a string\n- `Json.NET` library: to parse JSON files with .NET\n  - `JsonConvert.DeserializeObject()`:\n  - `File.WriteAllText()`: To write data to a file, pass in the data that you want to write\n  - `File.AppendAllText()`: by default, creates the file if it doesn't already exist\n\n\u003e I need ReadAllLines (from StreamReader?)\n\n```cs\n// Read data from files\nFile.ReadAllText($\"stores{Path.DirectorySeparatorChar}201{Path.DirectorySeparatorChar}sales.json\");\n\n// Parse data in files:\n// TERMINAL NuGet COMMAND: dotnet add package Newtonsoft.Json\nusing Newtonsoft.Json\nvar salesData = JsonConvert.DeserializeObject\u003cSalesTotal\u003e(salesJson);\nclass SalesTotal {\n  public double Total { get; set; }\n}\n\n// Write data to files\nvar data = JsonConvert.DeserializeObject\u003cSalesTotal\u003e(salesJson);\n\nFile.WriteAllText($\"salesTotalDir{Path.DirectorySeparatorChar}totals.txt\", data.Total.ToString());\n\n// Append data to files\nvar data = JsonConvert.DeserializeObject\u003cSalesTotal\u003e(salesJson);\n\nFile.AppendAllText($\"salesTotalDir{Path.DirectorySeparatorChar}totals.txt\", $\"{data.Total}{Environment.NewLine}\");\n\nvar appendedText = \"Added using File.AppendAllText\";\n\nstring newTextext = File.AppendAllText(Path.Combine(currDir, \"text.txt\"), $\"{appendedText}{Environment.NewLine}\");\nConsole.WriteLine(newTextext);\n```\n\n### Output for most of the above for code in Program.js\n\n```\n1. CURRENT DIRECTORY: C:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\n3. LOOP THRU FILES \u0026 GET FULL FILE PATH:\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\.gitignore\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\chord-intervals.json\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\notes.md\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\Program.cs\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\README.md\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\SystemIOClasses.csproj\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\SystemIOClasses.slnx\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\text.txt\nC:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\users.json\n------------------\n3.2 LOOP THRU FILES \u0026 GET FILE NAME (.json files only):\n.\\chord-intervals.json\n.\\users.json\n------------------\n4. Environment.SpecialFolder.MyDocuments: C:\\Users\\pc\\Documents\n4.2 Environment.SpecialFolder.Personal: C:\\Users\\pc\\Documents\n------------------\n5. DirectorySeparatorChar: \\\n------------------\n8. FileInfo (5 properties):\nFullName: C:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\\users.json\nName: users.json\nDirectory: C:\\Users\\pc\\Documents\\WebDev\\CodeYou\\CSharp\\M2\\SystemIOClasses\nExtension: .json\nCreationTime: 5/6/2026 5:51:38 PM\n------------------\n10. Directory.Exists (data folder):\nTrue\n------------------\n12. File.ReadAllText (text.txt):\nTesting File.WriteAllText\n------------------\n15. File.AppendAllText (text.txt):\nTesting File.WriteAllText\nAdded using File.AppendAllText\n```\n\n\u003c!-- https://jsonplaceholder.typicode.com/ --\u003e\n\n## Additional notes\n\n\u003e The `Path` and `Directory` classes in .NET provide methods for creating, deleting, moving, and enumerating directories. The `File` class provides methods for performing various file operations such as reading, writing, copying, and deleting files.\n\n1. Construct file and directory paths by using the Path class.\n2. Create directories and files by using the Directory and File classes.\n3. Enumerate directories and files by using the Directory class.\n\n- Common text file formats: TXT, CSV, JSON, XML\n- Path class:\n  - Combine\n  - GetDirectoryName\n  - GetFileName\n  - GetFileNameWithoutExtension\n  - GetExtension\n  - GetFullPath\n  - GetTempPath\n  - GetTempFileName\n\n```cs\n// Add Path class code/syntax examples here\n```\n\n- Directory class:\n  - CreateDirectory\n  - Exists\n  - GetCurrentDirectory\n  - GetFiles\n  - Delete\n  - Move\n  - EnumerateDirectories\n  - EnumerateFiles\n  - GetDirectories\n  - GetParent\n\n```cs\n// Add Directory class code/syntax examples here\n```\n\n- File class:\n  - Exists\n  - Create\n  - Delete\n  - Copy\n  - Move\n  - ReadAllText\n  - WriteAllText\n  - AppendText\n  - ReadAllLines\n  - `WriteAllLines`\n  - Open\n  - OpenRead\n  - OpenWrite\n  - OpenText\n  - GetAttributes\n  - SetAttributes\n\n```cs\n// Add File class code/syntax examples here\n```\n\n- Stream: FileStream, MemoryStream, NetworkStream\n- StreamReader (IDisposable interface)\n  - Read\n  - ReadLine\n  - ReadToEnd\n  - Peek\n  - Close\n  - Dispose\n- StreamWriter (IDisposable interface)\n  - Write\n  - WriteLine\n  - Flush\n  - Close\n  - Dispose\n\n```cs\n// StreamWriter code/syntax example\n// Is Encoding.UTF8 necessary?\nusing System;\nusing System.IO;\nusing System.Text;\n\nstring filePath = \"data.csv\";\n\nusing (StreamWriter writer = new StreamWriter(filePath, false, Encoding.UTF8)) {\n   // Write some data\n   writer.WriteLine(\"Name,Age,Occupation\");\n   writer.WriteLine(\"Elize Harmsen,30,Engineer\");\n   writer.WriteLine(\"Peter Zammit,25,Designer\");\n   writer.WriteLine(\"Niki Demetriou,35,Manager\");\n}\n\n// StreamReader code/syntax example\nstring filePath = \"data.csv\";\nusing (StreamReader reader = new StreamReader(filePath, Encoding.UTF8)) {\n   string line;\n   while ((line = reader.ReadLine()) != null) {\n         Console.WriteLine(line);\n   }\n}\n```\n\n- StringBuilder (System.Text namespace)\n- FileStream\n  - Open\n  - Create\n  - Read, ReadAsync\n  - Write, WriteAsync\n  - CopyTo, CopyToAsync\n  - Seek\n  - Length\n  - Position\n  - CanRead\n  - CanWrite\n  - CanSeek\n  - Flush, FlushAsync\n  - Close\n  - Dispose\n  - FileAccess: Read, Write, or ReadWrite\n  - FileShare: None, Read, Write, or ReadWrite\n  - FileMode: Append, Create, CreateNew, Open, OpenOrCreate, or Truncate\n  - FileOptions: None, Asynchronous, SequentialScan, RandomAccess, or WriteThrough\n  - SKIP: BinaryReader and BinaryWriter classes\n\n```cs\n// Simple example of how to use FileStream to write data to a file\nusing System;\nusing System.IO;\n\nstring path = \"example.txt\";\nbyte[] data = System.Text.Encoding.UTF8.GetBytes(\"Hello, FileStream!\");\n\nusing (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) {\n    fs.Write(data, 0, data.Length);\n}\n\n// How you can read data from a file using FileStream\nusing System;\nusing System.IO;\n\nstring path = \"example.txt\";\nbyte[] buffer = new byte[1024]; // Adjust buffer size as needed\n\nusing (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))\n{\n    int bytesRead = fs.Read(buffer, 0, buffer.Length);\n    string readData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead);\n    Console.WriteLine(\"Data read from file: \" + readData);\n}\n\n// more comprehensive coding example that demonstrates reading, writing, and seeking within a file\n```\n\n.....................................................................\n\nJSON:\n\n- Serialization is used to convert a C# object into a JSON string\n- Deserialization is the reverse process: Convert a JSON string back into a C# object\n  - it is particularly useful when working with APIs or external data sources\n- `System.Text.Json` namespace\n  - JsonSerializer: for **converting**\n  - JsonDocument: or **reading and parsing** JSON data without needing to deserialize them\n  - JsonElement: for **accessing and manipulating** JSON data\n- JsonSerializer\n  - Serialize: object -\u003e JSON\n  - Deserialize: JSON -\u003e object\n\n```cs\nusing System;\nusing System.Text.Json;\nusing System.Text.Json.Serialization;\n\npublic class Employee\n{\n    public string Name { get; set; }\n    public int Age { get; set; }\n    public string Address { get; set; }\n}\n\n// In Program.cs\n// Serialize\nvar customer = new Employee { Name = \"Anette Thomsen\", Age = 30, Address = \"123 Main St\" };\nstring jsonString = JsonSerializer.Serialize(customer);\nConsole.WriteLine(jsonString);\n// Output: {\"Name\":\"Anette Thomsen\",\"Age\":30,\"Address\":\"123 Main St\"}\n\n// Deserialize\nstring jsonString2 = @\"{\"\"Name\"\":\"\"Anette Thomsen\"\",\"\"Age\"\":30,\"\"Address\"\":\"\"123 Main St\"\"}\";\nvar customer = JsonSerializer.Deserialize\u003cEmployee\u003e(jsonString2);\nif (customer != null)\n{\n    Console.WriteLine($\"Name: {customer.Name}, Age: {customer.Age}, Address: {customer.Address}\");\n}\nelse\n{\n    Console.WriteLine(\"Deserialization failed.\");\n}\n// Output: Name: Anette Thomsen, Age: 30, Address: 123 Main St\n\n// NEED MORE EXAMPLES?\n```\n\n. . . . . . . . . . . . . `DONE` . . . . . . . . . . . . .\n\n- JsonSerializerOptions ----\u003e `DONE`\n  - DefaultIgnoreCondition\n  - WriteIndented\n  - IncludeFields\n  - PropertyNameCaseInsensitive\n  - AllowTrailingCommas\n  - IgnoreNullValues\n  - Encoder\n  - IgnoreReadOnlyProperties\n  - WhenWritingNull\n  - WhenWritingDefault\n  - RespectRequiredConstructorParameters\n  - PreferredObjectCreationHandling\n  - Converters\n  - DefaultBufferSize\n  - AllowOutOfOrderMetadataProperties\n  - NumberHandling\n  - MaxDepth\n  - ReferenceHandler, ReferenceHandler.Preserve\n  - Converters\n- `[JsonIgnore]`: specify conditional exclusion via `Condition` property\n  - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]\n  - [JsonIgnore(Condition = JsonIgnoreCondition.Never)]\n  - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]\n- DefaultIgnoreCondition (?)\n- `required` modifier = `[JsonRequired]`\n- `JsonSerializer.Deserialize(\u003cobjType\u003ejsonString`\n- JsonRequiredAttribute?\n- JsonPropertyInfo.IsRequired?\n- DefaultJsonTypeInfoResolver\n- JsonObjectCreationHandling\n  - Replace\n  - Populate\n- JsonObjectCreationHandlingAttribute\n  - Handling\n  - Populate\n\n\u003e WTF? Why have options on what object members to serialize/deserialize?\n\u003e Manage serialization and deserialization of complex objects: another exception/edge-case section!!!\n\n\u003e ONLY ADD CODE BLOCKS FOR METHODS/PROPERTIES THAT ARE USED IN THE MS LEARN EXAMPLES - **SKIP THE REST!** And that goes for all OOP lessons and going forward into module 3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernix13%2Fcsharp-system-io-classes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkernix13%2Fcsharp-system-io-classes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernix13%2Fcsharp-system-io-classes/lists"}