Dynamic themes in ASP.NET 2.0 (C#)

by Damiaan Peeters 22. March 2008 12:11

Today I looked at the ASP.NET 2.0 Themes.  I've been using them for a long time, but I never knew that you can set a default theme in the web.config.

Just add this to the system.web section

<pages styleSheetTheme="Black"/>

Further more I needed to change my theme dynamically.  I found an interesting article on this topic on CodeProject.

CodeProject: Dynamic themes in ASP.NET 2.0 (C#).

Visual Studio 2005 Code Snippet Editor

by Damiaan Peeters 21. March 2008 11:44

Ever wondered how to change or add code snippets to Visual Studio 2005?  As you probably found out, you have to change or create some XML.  On techRepublic you can find an article on "Creating custom Visual Studio 2005 Code Snippets".

But did you know codeplex is hosting a "Editor for creating and modifying Visual Studio 2005 Code Snippets".  Snippy - Visual Studio Code Snippet Editor

export a DHCP reservations to a text file

by Damiaan Peeters 19. March 2008 16:05

On the internet you can find tons of information about exporting a dhcp reservationlist (from Microsoft DHCP server).

Today, I tried to do that using NETSH.  Unfortunately i always received the following error:

The following command was not found: dhcp 

If you see this error, you should check if the DHCP is available.  To do this, enter the next command:

netsh show helper

If DHCP is not shown in the list, you can add it, by running the following command on your command prompt:

netsh add helper dhcpmon.dll

After you added the helper, you will be able to run all commands regarding the dhcp.  For example get the server reservation list:

netsh -r MyDhcpServernameOrIpAddress dhcp server dump 

 

Http POST to webserver using C#

by Damiaan Peeters 6. March 2008 11:38

I 've written some time ago a HTML scraper to search the VIES VAT number Validation web site of the European Union.  The service offered no web service at that time, so I needed to use the HTTP POST method.

The code is not too difficult.

[more]

    private readonly string Url = "http://ec.europa.eu/taxation_customs/vies/cgi-bin/viesquer";
private readonly string Referer = "http://ec.europa.eu/taxation_customs/vies/en/vieshome.htm";
List<Exception> Exceptions = null;
     ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Lang=EN";
postData += ("&VAT=" + VatNumber);
postData += ("&MS=" + CountryCode);
postData += ("&ISO=" + CountryCode);
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(this.Url);
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Referer = Referer;
myRequest.ContentLength = data.Length;
myRequest.ProtocolVersion = HttpVersion.Version10;
myRequest.Method = "POST";
Stream newStream = myRequest.GetRequestStream();
// Send the data.
     newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse resp = null;
try
     {
resp = (HttpWebResponse)myRequest.GetResponse();
}
catch (Exception ex)
{
Exceptions.Add(ex);
}
     StreamWriter myWriter = null;
try
     {
myWriter = new StreamWriter(resp.GetResponseStream());
myWriter.Write(data);
}
catch (Exception e)
{
Exceptions.Add(e);
return VatCheckOk.NotChecked;
}
finally
     {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)myRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
string result = sr.ReadToEnd();
// Close and clean up the StreamReader
         sr.Close();
}
If i remember well, i used the result string to check for the string: "Yes, Valid number".

Implementing Finalize and Dispose to Clean Up Unmanaged Resources

by Damiaan Peeters 2. March 2008 12:04

I found some design patterns about implementing Dispose & Destructors in C#.

Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected Finalize on an object (destructor syntax in C# and C++). The garbage collector calls this method at some point after there are no longer any valid references to the object.

Implementing Finalize and Dispose to Clean Up Unmanaged Resources

Who.I.am

Certified Umbraco, .net and Azure developer, seo lover. Magician in my spare time.

Month List