Zum Hauptinhalt springen
IT NachrichtenKlook Promo Code: 25% Off October 2026(03.10.2026 um 07:00 Uhr)
••••
IT NachrichtenCCleaner unter Windows 7 nutzen – ist das möglich?(03.10.2026 um 07:00 Uhr)
•••
IT NachrichtenOllama unterstützt jetzt Entscheidungsmodelle(03.10.2026 um 05:30 Uhr)
•••
IT NachrichtenKlook Promo Code: 25% Off October 2026(03.10.2026 um 07:00 Uhr)
••••
IT NachrichtenCCleaner unter Windows 7 nutzen – ist das möglich?(03.10.2026 um 07:00 Uhr)
•••
IT NachrichtenOllama unterstützt jetzt Entscheidungsmodelle(03.10.2026 um 05:30 Uhr)
•••
Intelligence View
⚡ tsecurity.de Intelligence

Day 10 of 30-Day .NET Challenge: File Paths

Introduction The article demonstrates the built-in functions while working with file system paths. It makes it easier to handle file paths. Learning Objectives…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




Introduction



The article demonstrates the built-in functions while working with file system paths. It makes it easier to handle file paths.






Learning Objectives




  • Learn about constants and functions in the System.IO namespace






Prerequisites for Developers




  • How to use Visual Studio or Visual Studio Code


  • Handling variables, employing string interpolation, and displaying output.







Getting Started






How to determine the current directory?



The System.IO contains a method to expose the full path of the current directory. To begin, create a static class file called “FilePath.cs” within the console application. Insert the provided code snippet into this file.




    public static class FilePath
{
/// <summary>
/// Outputs
/// D:\Workspace\30DayChallenge.Net\30DayChallenge.Net\bin\Debug\net8.0
/// </summary>
public static void DisplayCurrentDirectory()
{
Console.WriteLine(Directory.GetCurrentDirectory());
}
}






Execute the code from the main method as follows




    #region Day 10 - File Path

FilePath.DisplayCurrentDirectory();

#endregion









Console Output






D:\Workspace\30DayChallenge.Net\30DayChallenge.Net\bin\Debug\net8.0









How to work with special directories?



The code below provides the path to the Windows My Documents folder equivalent or the user’s HOME directory, regardless of the operating system, including Linux. To do that add another method into the same static class as shown below




    /// <summary>
/// Outputs
/// C:\Users\admin\Documents
/// </summary>
public static void DisplaySpecialDirectory()
{
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
}






Execute the code from the main method as follows




    #region Day 10 - File Path

FilePath.DisplaySpecialDirectory();

#endregion









Console Output






    C:\Users\admin\Documents









How to get OS path characters?



Various operating systems utilize distinct characters for separating directory levels. The framework automatically interprets the separator character relevant to the operating system being used.



To do that add another method into the same static class as shown below




    /// <summary>
/// Outputs
/// For windows: \sample
/// </summary>
public static void DisplayOSPathCharacters()
{
Console.WriteLine($"For windows: {Path.DirectorySeparatorChar}sample");
}






Execute the code from the main method as follows




    #region Day 10 - File Path

FilePath.DisplayOSPathCharacters();

#endregion









Console Output






    For windows: \sample 









How to get filename extensions?



The Path class also exposes a method to get an extension of any filename passed as a parameter. To do that add another method into the same static class as shown below




    /// <summary>
/// Outputs
/// .json
/// </summary>
public static void DisplayFileExtension()
{
Console.WriteLine("sample.json");
}






Execute the code from the main method as follows




    #region Day 10 - File Path

FilePath.DisplayFileExtension();

#endregion









Console Output






    .json









Complete Code on GitHub



GitHub — ssukhpinder/30DayChallenge.Net






C# Programming🚀



Thank you for being a part of the C# community! Before you leave:






If you’ve made it this far, please show your appreciation with a clap and follow the author! 👏️️



Follow us: X | LinkedIn | Dev.to | Hashnode | Newsletter | Tumblr



Visit our other platforms: GitHub | Instagram | Tiktok | Quora | Daily.dev



More content at C# Programming

🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
IoC Intelligence
1 Indikatoren · Defanged · STIX 2.1
dev[.]to
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
3 Knoten · 2 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 10 of 30-Day .NET Challenge: File Paths

Thematisch verwandte Begriffe: 30Day, Challenge, File, Paths · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag