System.IO.FileInfo Extension Methods

FileInfo.GetFileNameWithoutExtension Method

A FileInfo extension method that gets file name without extension.

Syntax

string GetFileNameWithoutExtension(FileInfo @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_IO_FileInfo_GetFileNameWithoutExtension
     {
         [TestMethod]
         public void GetFileNameWithoutExtension()
         {
             // Type
             var @this = new FileInfo("Fizz.txt");
 
             // Examples
             string value = @this.GetFileNameWithoutExtension(); // return "Fizz";
 
             // Unit Test
             Assert.AreEqual("Fizz", value);
         }
     }
 }
                

FileInfo.ReadToEnd Method

A FileInfo extension method that reads the file to the end.

Syntax

string ReadToEnd(FileInfo @this,long position)

Parameters

@this
The @this to act on.
position
(Optional) the position.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_IO_FileInfo_ReadToEnd
     {
         [TestMethod]
         public void ReadToEnd()
         {
             // Type
             var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadToEnd.txt"));
 
             // Intialization
             using (FileStream stream = @this.Create())
             {
                 stream.WriteByte(0);
             }
 
             // Examples
             string value = @this.ReadToEnd(); // return "\0";
 
             // Unit Test
             Assert.AreEqual("\0", value);
         }
     }
 }
                

Last edited Nov 23, 2013 at 6:54 PM by Jonathan_Magnan, version 1