When I try to open my app config file by
ConfigurationManager.OpenExeConfiguration(filePath);
it returns an exception, because there is no file. But I need to create this file in this case. But as I know, config file create by adding at VS like How to: Add an Application Configuration File to a C# Project
So, how to create this file in other way?
If you really want to create an empty config file at runtime you can do something like this, but note that if the config file already exists this code will overwrite it:
System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
sb.AppendLine("<configuration>");
sb.AppendLine("</configuration>");
string loc = Assembly.GetEntryAssembly().Location;
System.IO.File.WriteAllText(String.Concat(loc, ".config"), sb.ToString());