Posts

Donate

Uncompress GZip Response Using WebClient In C#

In a scenario where you want to download xml data using webclient, the response from firefox or any browser will display the xml file correctly. However, using a web request/webclient.downloadstring to download the xml file, the response is somewhat corrupted or in hashed form. The response headers are the following: 1. Content-Type - application/xml 2. Content-Encoding - gzip As you can see, the content encoding is of type gzip . The solution is to override the web request method to something like this: class DecompressGzipResponse : WebClient { protected override WebRequest GetWebRequest (Uri address) { HttpWebRequest request = (HttpWebRequest) base .GetWebRequest(address); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; return request; } } //to use this in the program (main function) DecompressGzipResponse client = new DecompressGzipResponse (); Listi

How To Convert Exponent to Decimal Notation In C#

Good morning, Here's how you convert exponent value to C# using decimal.parse() function. Make sure to pass NumberStyles.Float from System.Globalization namesapce in the second parameter of the function. string land_area = "1.21445e-007" .ToUpper(); decimal dec = decimal .Parse(land_area, System.Globalization.NumberStyles.Float);

How To Count Number Of Character Or ElementOccurrences In A String Using C#

Hello All, In order to count the occurences of a certain element or character in a string, you need to perform the split() function and subtract the length with one to get the actual count. int count_li = tempListSource.Split( new string []{ "<li>" }, StringSplitOptions.RemoveEmptyEntries).Length - 1;

Reset Seed In MySQL Table

To reset the seed of a MySQL table, perform alter table statement and set the AUTO_INCREMENT value to 1. ALTER TABLE tblProduct AUTO_INCREMENT = 1; Cheers!

.NET Framework Version Checker in your PC Using C#

Here's a repost of a .NET Version Checker I found in the internet. const string regLocation = "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP" ; static void Main( string [] args){ Console.WriteLine( ".NET Framework versions installed" ); Console.WriteLine( "---------------------------------" ); Console.WriteLine(); RegistryKey masterKey = Registry.LocalMachine.OpenSubKey(regLocation); RegistryKey tempKey; if (masterKey == null ) { Console.WriteLine( "Null Key!" ); } else { string [] SubKeyNames = masterKey.GetSubKeyNames(); for ( int i = 0; i < SubKeyNames.Length; i++) { tempKey = Registry.LocalMachine.OpenSubKey (regLocation + "\\" + SubKeyNames[i]); Console.Write(SubKeyNames[i]); Console.WriteLine( "\t

The Error: 417 "Expectation Failed." During Webrequest In C#

Here's a solution on how to fix the 417 expectation failed error during WebRequest In C#. System.Net.ServicePointManager.Expect100Continue = false ;

How To Insert Date Object In MySQL Using C#.NET

Hello, To insert date object using C#.net in MySQL db,use the code below: string query = String.Format( "Insert into tbllistings(DateRegistered)" + "values(DATE_FORMAT({0}, '%Y-%m-%d %h:%m:%s'))" ,objJobs.DateRegistered); The key to the solution is using the MySQL Date format function.

Disable WindowsForms Form From Being Resized At Design Time In C#

Here's a snippet on how to prevent or disable winforms form object from being resized at design time. this .MaximumSize = new System.DrawingSize(500, 400); this .MinimumSize = new System.DrawingSize(500, 400);

MySQL Date Range Query (Using Logical Operators)

Here's another version using logical operators in MySQL. 1: select date_format(date_purchased, '%m/%d/%Y' ) as dates, 2: url from dbcommerce.tblproducts 3: where date_format(date_purchased, '%m/%d/%Y' ) >= '04/30/2011' 4: and date_format(date_purchased, '%m/%d/%Y' ) <= '05/30/2011' 5: order by date_purchased asc ;

MySQL Date Range Query Example

Here is an example to query MySQL Date Range given the date field is of type TimeStamp. The date_format() will remove the time part in comparing. select date_format(date_purchased, '%m/%d/%Y' ) as dates, url from dbCommerce.tblproducts where date_format(date_purchased, '%m/%d/%Y' ) between '04/30/2011' and '05/30/2011' order by date_purchased asc ;

Donate