コード例 #1
0
        /// <devdoc>
        /// Load the xml file storage.
        /// </devdoc>
        private XmlDocument LoadXmlFile(string fileName)
        {
            XmlDocument doc = new XmlDocument();

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                try
                {
                    using (ConfigurationProtector protector = runtimeConfigurationView.GetConfigurationProtector(CurrentSectionName))
                    {
                        byte[] fileBytes = new byte[fs.Length];
                        fs.Read(fileBytes, 0, fileBytes.Length);
                        if (fileBytes.Length > 0)
                        {
                            fileBytes = protector.Decrypt(fileBytes);
                            doc.Load(new MemoryStream(fileBytes));
                        }
                    }
                }
                catch (XmlException e)
                {
                    throw new ConfigurationException(SR.ExceptionInvalidXmlStorageFile(fileName), e);
                }
            }


            return(doc);
        }