You should use System.Security.SecurityElement.Escape in C# to escape special characters in XML and not System.Web.HttpUtility.HtmlEncode

You should use the function System.Security.SecurityElement.Escape and not the function System.Web.HttpUtility.HtmlEncode to escape special characters in XML if you don’t want the characters like éûÉ to be converted to &#233;&#251;&#201; which is permit able but not necessary en can result in long xml fields. var escapedXml = System.Security.SecurityElement.Escape(@"&<>’""’éûÉغ"); Console.WriteLine(escapedXml); // …

Adding a folder to the .NET assembly search path, to prevent the error Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The system cannot find the file specified.

If you use the XmlConfigurator.Configure() . log4net function in a setup custom action to initialize the log4net logging, you can get the error: Could not load file or assembly ‘log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821’ or one of its dependencies. The system cannot find the file specified. This is because the msi …

Debug you’re Microsoft Visual Studio 2008 setup project output msi with Debugger.break()

If you want to start the debugger after installation of you’re product with a Microsoft Visual Studio 2008 setup msi package, use a Installer class and custom actions and then add a Debugger.Break() on the AfterInstall event: [RunInstaller(true)] public partial class ProjectInstaller : Installer { public ProjectInstaller() { InitializeComponent(); } …

How to convert a unicode string to an ASCII string

To convert a unicode string to an ASCII string, use: public void ConvertUnicodeStringToAsciiString() { // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding unicode = Encoding.Unicode; // Convert the string into a byte[]. byte[] unicodeBytes = unicode.GetBytes("van ’t huis"); // Perform the conversion from one encoding to the other. …

Export images from SQL Server database with C# 3.5

If you want to export images from a SQL Server database you could use the following code: public void ExportImagesFromDatabase() { var exportPath = @"C:\Temp"; if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } var imagesTable = GetImagesFromDatabase("select [ImageColumn] from [ImageTable]"); var rowCounter = 0; foreach (DataRow row in imagesTable.Rows) { if (row.ItemArray.Length > …