private void RefreshExpressInfo() { DirectoryInfo directoryInfo = new DirectoryInfo(WorkDirectory); FileInfo fileInfo = directoryInfo.GetFiles("config.xml").FirstOrDefault(); if (fileInfo != null) { FileStream fileStream = new FileStream(fileInfo.FullName, FileMode.Open); try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExpressInfo)); expressInfo = (ExpressInfo)xmlSerializer.Deserialize(fileStream); } finally { if (fileStream != null) { ((IDisposable)fileStream).Dispose(); } } } }
void RefreshExpressInfo() { DirectoryInfo dir = new DirectoryInfo(WorkDirectory); //查找该目录下的 var configFile = dir.GetFiles("config.xml").FirstOrDefault(); if (configFile != null) { string sDirectory = Himall.Core.Helper.IOHelper.urlToVirtual(configFile.FullName); XmlSerializer xs = new XmlSerializer(typeof(ExpressInfo)); byte[] b = Himall.Core.HimallIO.GetFileContent(sDirectory); string str = System.Text.Encoding.Default.GetString(b); MemoryStream fs = new MemoryStream(b); expressInfo = (ExpressInfo)xs.Deserialize(fs); //using (FileStream fs = new FileStream(configFile.FullName, FileMode.Open)) //{ // XmlSerializer xs = new XmlSerializer(typeof(ExpressInfo)); // expressInfo = (ExpressInfo)xs.Deserialize(fs); //} } }