Convert To Legal File Name : File Name « File Stream « C# / C Sharp






Convert To Legal File Name

     

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
using System.Drawing.Imaging;
using System.Reflection;

namespace SuchSofts.OpenImage.Lib.Operation
{
    internal class CommonOperations
    {

        public static string ConvertToLegalFileName(string name)
        {
            //replace \ / : * ? " < > | with #
            Regex regexCharFilter = new Regex("[\\u005C|/|:|\\u002A|\\u003F|\"|<|>| \\u007C]");
            string fileName = regexCharFilter.Replace(name, "#");
            string old = fileName;
            if (fileName == "")
            {
                fileName = "#";
            }
            return fileName;
        }

    }
}

   
    
    
    
    
  








Related examples in the same category

1.Query file name with Linq
2.Clean File Name
3.Retrieves the date from the beginning of the WinSat filename and creates a datetime object from it
4.Get File Name
5.Get File Name From Path
6.Extracts a path part of a full path filename, searching for the last directory separator or column.
7.Creates a relative path from absolute pathfilename and a reference path.
8.Get file extension
9.Restrict a list of files to valid extensions only
10.Get Content Type by Extension
11.Get Full Path Without Extension
12.Full Name Without Extension
13.Name Without Extension
14.ImageFormat to Extension
15.Gets the extension without the dot
16.Get Image Type Extension