String - UrlDecodeToBytes

Converts a URL-encoded string into a decoded array of bytes.

Try it

public static string FileName = "test.txt";

public static void Main()
{
    string urlString = "http%3a%2f%2ftest%23+space+123%2ftext%3fvar%3dval%26another%3dtwo";
	
	//C# Extension Method: String - UrlDecodeToBytes
    var bytes = urlString.UrlDecodeToBytes();
	
	var file = FileName.ToFileInfo();
	
	// C# Extension Method: FileInfo - WriteAllBytes
	file.WriteAllBytes(bytes);

    Console.WriteLine(file.ReadAllText());
}

View Source
using System;
using System.Text;
using System.Web;

public static partial class Extensions
{
    /// <summary>
    ///     Converts a URL-encoded string into a decoded array of bytes.
    /// </summary>
    /// <param name="str">The string to decode.</param>
    /// <returns>A decoded array of bytes.</returns>
    public static Byte[] UrlDecodeToBytes(this String str)
    {
        return HttpUtility.UrlDecodeToBytes(str);
    }

    /// <summary>
    ///     Converts a URL-encoded string into a decoded array of bytes using the specified decoding object.
    /// </summary>
    /// <param name="str">The string to decode.</param>
    /// <param name="e">The  object that specifies the decoding scheme.</param>
    /// <returns>A decoded array of bytes.</returns>
    public static Byte[] UrlDecodeToBytes(this String str, Encoding e)
    {
        return HttpUtility.UrlDecodeToBytes(str, e);
    }
}