FileInfo - Rename

A FileInfo extension method that renames a file name.

Try it

public static string FileName = "test.txt";

public static void Main()
	var file = FileName.ToFileInfo();
	Console.WriteLine("File Name: {0}", file.FullName);
	// C# Extension Method: FileInfo - Rename
	Console.WriteLine("New file Name: {0}", file.FullName);

private static void SaveFile()
	var html =
    @"<!DOCTYPE html>
<h1>This is <b>bold</b> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
<h2>This is <i>italic</i> heading</h2>
</html> ";

View Source
using System.IO;

public static partial class Extensions
    /// <summary>
    ///     A FileInfo extension method that renames.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="newName">Name of the new.</param>
    /// ###
    /// <returns>.</returns>
    public static void Rename(this FileInfo @this, string newName)
        string filePath = Path.Combine(@this.Directory.FullName, newName);