Posts

Donate

GeckoFX How To Trigger Or Fire JavaScript _doPostBack() Method

Here's how you fire a _doPostBack() in ASP.NET using GeckoFX. //fire js method using (AutoJSContext context = new AutoJSContext( this .JSContext)) { string result; context.EvaluateScript( string .Format( "javascript:__doPostBack('{0}','')" , paramControlName), out result); } Cheers!

GeckoFX DocumentText Similar To Webbrowser Control (C#)

In a traditional webbrowser control, you can get the page source like this: string pageSource = webbrowser1.DocumentText; However, in GeckoFX webbrowser, there's no DocumentText property. A workaround is to get the InnerHtml property of html tag using the code below: string pageSource = string .empty; if (! string .IsNullOrEmpty( this .Document.GetElementsByTagName( "html" )[0].InnerHtml)) pageSource = this .Document.GetElementsByTagName( "html" )[0].InnerHtml; Cheers!

GeckoFx getElementByID() click() Method Missing

In an application that i am creating using Gecko FX version 15, I noticed that getElementsByTagName() has an invoke member click() as shown below: this .Document.GetElementsByTagName(geckoElement.TagName)[indexSearchElement].Click(); But missing in getElementByID(). After experimenting for a few hours, I came up with the solution below: ((GeckoHtmlElement) this .Document.GetElementById(elemId)).Click(); The trick was to cast it as GeckoHtmlElement. Greg

WebClient Slow In Crawling Or Web Scraping A Website In C#

Here's a tip i got from stack overflow on webclient slow on web crawling. 1 2 3 ServicePointManager.DefaultConnectionLimit = int .MaxValue; ServicePointManager.MaxServicePoints = int .MaxValue; ServicePointManager.MaxServicePointIdleTime = 0; I simply changed the default connection limit and max service points to a numeric value. Then, the crawling starts to speed up. Greg

WebRequest Url Not Returning Correct Page Source If Proxynull Not Used As Part Of Url Query String (Web Scraping) In C#

In one of the sites im crawling, I encountered a situation where a site needs a query string like proxynull = 90B69303-3A61-4482-AF0725FDA1DAE548 or appended into a url like this http://samplesite/bin/jobs_list.cfm?proxynull=90B69303-3A61-4482-AF0725FDA1DAE548 I wonder if i could just use the post data and use the url without the proxynull query string like this http://samplesite/bin/jobs_list.cfm to scrape the website. After series of experimentation, the solution is to set the webproxy of the webrequest object to default proxy similar to the code below: ((HttpWebRequest)webRequest).Proxy = WebRequest.DefaultWebProxy; in order to use the url(http://samplesite/bin/jobs_list.cfm) without proxynull.

Cannot find JavaScriptSerializer in .Net 4.0

These are the steps for using it in .NET 4.0 1. Create a new console application 2. Change the target to dot.net 4 instead of Client Profile 3. Add a reference to System.Web.Extensions (4.0) 4. Got access to JavaScriptSerializer in Program.cs now :-) Source: Cannot Find Javascript Serializer in .NET 4.0

Remove HTML Tags In An XML String Document Using Regular Expressions (REGEX) In C#

Here's a regex pattern that will match html tags that are present in an xml string document. Where xml, node1, node2, node3, node4, node5, node6 and node7 are xml tags. node1 could represent a valid xml tag name like employername or similar tag names. xmlStringData = Regex.Replace(xmlStringData, @"<((\??)|(/?)|(!))\s?\b(?! (\b(xml|node1||node2|node3|node4|node5|node6|node7)\b))\b[^>]*((/?))>" , " " , RegexOptions.IgnoreCase); Greg

Optimizing SQL TOP Queries In MSSQL Database

Here's an interesting article on optimizing queries using Top statement to filter result sets: Why SQL Top may slow down your query? The solutions are the following: 1. using Hash joins SELECT TOP 5 [Articles].Id ,CountryCategories.Name ,CityCategories.Name FROM [Articles] INNER HASH JOIN CategoryCountry2Articles ON [Articles].Id = CategoryCountry2Articles.IdArticle INNER HASH JOIN CountryCategories ON CountryCategories.Id = CategoryCountry2Articles.IdCountry INNER HASH JOIN CategoryCity2Articles ON [Articles].Id = CategoryCity2Articles.IdArticle INNER HASH JOIN CityCategories ON CityCategories.Id = CategoryCity2Articles.IdCity WHERE CountryCategories.Name = 'country1' AND CityCategories.Name = 'city4' 2. Using Variables. DECLARE @topCount INT SET @topCount = 5 SELECT TOP (@topCount) (...) I am pretty much interested why using variables is much faster. Compared with other findings ...

IOrderedQueryable<T> Extension Method (C#)

Here's a modified version of Nick Harrison's IOrderedQueryable extension method in his dynamic linq query post: static class IQueryableExtensions { public static IOrderedQueryable<TSource> GenericEvaluateOrderBy<TSource>( this IQueryable<TSource> query, string propertyName) { var type = typeof (TSource); var property = type.GetProperty(propertyName); var parameter = Expression.Parameter(type, "p" ); var propertyReference = Expression.Property(parameter, property); //p.ProductName var sortExpression = Expression.Call( typeof (Queryable), "OrderBy" , new Type[] { type, property.PropertyType }, query.Expression, Expression.Quote(Expression.Lambda(Expression.MakeMemberAccess(parameter, property), parameter))); return query.Provider.CreateQuery<TSource>(sortExpression) as IOrderedQueryable<TSource...

Regular Expression Remove Day Name And Date Suffix In C#

In a situation where i want to format this date value from (Tuesday 19th March 2013) to (19 March 2013). I made a regular expression by applying look behind approach and ends with behavior in strings. Here's the expression: indicatorDate = Regex.Replace(indicatorDate, @"(\b[A-Za-z]*day\b)|((?<=[0-9])[a-zA-z]{2})" , string .Empty, RegexOptions.IgnoreCase); :)

Donate