Search code examples
visual-studioutf-8character-encoding

Save all files in Visual Studio project as UTF-8


I wonder if it's possible to save all files in a Visual Studio 2008 project into a specific character encoding. I got a solution with mixed encodings and I want to make them all the same (UTF-8 with signature).

I know how to save single files, but how about all files in a project?


Solution

  • Since you're already in Visual Studio, why not just simply write the code?

    foreach (var f in new DirectoryInfo(@"...").GetFiles("*.cs", SearchOption.AllDirectories)) {
      string s = File.ReadAllText(f.FullName);
      File.WriteAllText (f.FullName, s, Encoding.UTF8);
    }
    

    Only three lines of code! I'm sure you can write this in less than a minute :-)