Debugging a WCF service on Windows 7 and IIS 7

0 Comments

I created and deployed a WCF service, created with Microsoft Visual Studio 2008, to IIS 7 on Windows 7 and I got the error message: Unable to start debugging on the web server. Could not

Show all encodings and codepages on a Windows server in C#

0 Comments

If you want to show all encodings of a Windows server in C# in sorted order, use the code: // Get all encodings know on this server EncodingInfo[] encodings = Encoding.GetEncodings(); // Sort EncodingInfo array

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.

4 Comments

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

How to convert a string containing XML to XDocument

0 Comments

If you want to convert a string containing XML to a XDocument object, use: var document = XDocument.Parse(@"<?xml version=""1.0""?><root></root>"); For converting XmlDocument to XDocument and vice versa, see: http://blogs.msdn.com/marcelolr/archive/2009/03/13/fast-way-to-convert-xmldocument-into-xdocument.aspx

How to convert a unicode string to an ASCII string

2 Comments

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[]

Export images from SQL Server database with C# 3.5

0 Comments

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]

ASP .NET – Get page filename from request url

0 Comments

If you want to get the page filename from the current request url in ASP .NET you can use: string page = Path.GetFileName(Request.Url.LocalPath).ToLower(); This can be used to switch logica in de master page.