Posts

Showing posts from November, 2011

Reading an XML file

Easy way of reading an xml file without linq or xpath XmlDocument comment = new XmlDocument(); //full path. use .Load for URL comment.LoadXml(File.ReadAllText(myfile.FullName)); XmlNodeList xnList = comment.SelectNodes("/RootNode"); foreach (XmlNode xn in xnList) { title = xn["Title"].InnerText; description = xn["Content"].InnerText; }

PowerShell | Load assemly the right way

We often want to load an assembly into our environment. Even though there is not much to it, there are a few ways to achieve it, ones better than others. So far, I've used: [void][Reflection.Assembly]::LoadFrom("assembly.dll") Turns out, using PowerShell or .NET, our used dll may become locked. Even if this is not an issue for us, if we could improve this load to prevent file locks, and prevent future issues. So we can do that by loading the file strem into the memory, instead of using its file system location. [void][Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes("assembly.dll"))