try
            
{

                
// Extract the config file path from the default .config file

                
string configPath = ConfigurationManager.AppSettings["configPath"];

                
// If the default .config file is missing

                
if (configPath == null)
                
{

                    
// Get the assembly

                    Assembly asm 
= Assembly.GetExecutingAssembly();

                    
string exeRoot = asm.Location;

                    
try
                    
{

                        
// And try explicitly loading it

                        Configuration config 
= ConfigurationManager.OpenExeConfiguration(exeRoot);

                        configPath 
= config.AppSettings.Settings["configPath"].Value;

                        config 
= null;

                        
// And if it is still not found

                        
if (configPath == null)
                        
{

                            
// Directly try to load the file from the same path as the .exe

                            
string configRoot = Path.GetDirectoryName(exeRoot);

                            configPath 
= configRoot + "LineCounterAdding.config";

                        }


                    }


                    
catch (ConfigurationErrorsException)
                    
{

                        
// Directly try to load the file from the same path as the .exe in all other cases

                        
string configRoot = Path.GetDirectoryName(exeRoot);

                        configPath 
= configRoot + "LineCounterAddin.config";

                    }


                    asm 
= null;

                }


                
// Replace the $(PersonalFolder) macro with the users MyDocuments path

                configPath 
= configPath.Replace("$(PersonalFolder)", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

                
// Load the config file
                XmlDocument doc;
                
if (File.Exists(configPath))
                
{

                    doc 
= new XmlDocument();

                    doc.Load(configPath);

                    configPath 
= null;

                }


            }


            
catch
            
{
            }


            
finally
            
{

            }
posted on 2006-11-29 15:54  cinger  阅读(391)  评论(0)    收藏  举报