BF2Statistics.HostsFile.Save C# (CSharp) Method

Save() public method

Saves all currently set domains and IPs to the hosts file
public Save ( ) : void
return void
        public void Save()
        {
            using (FileStream Str = HostFile.Open(FileMode.Truncate, FileAccess.Write, FileShare.Read))
            using (StreamWriter Writer = new StreamWriter(Str))
            {
                foreach (KeyValuePair<String, IPAddress> line in Entries)
                    Writer.WriteLine(String.Format("{0}\t{1}", line.Value, line.Key));
            }
        }

Usage Example

        /// <summary>
        /// Removes all gamespy related redirects in the specified hosts file container
        /// </summary>
        /// <param name="HostFile"></param>
        private static void RemoveRedirects(HostsFile HostFile)
        {
            // Remove Gamespy Addresses. Use a Bitwise OR here to execute both methods
            if (HostFile.Remove(Bf2StatsHost) | HostFile.RemoveAll(GamespyHosts))
            {
                // Save Changes
                HostFile.Save();

                // Flush the Cache of the gamespy hosts
                foreach (string host in GamespyHosts)
                {
                    DnsFlushResolverCacheEntry(host);
                }

                // Flush stats server
                DnsFlushResolverCacheEntry(Bf2StatsHost);
            }
        }
All Usage Examples Of BF2Statistics.HostsFile::Save