Posts

Donate

The name 'ViewData' does not exist in the current context

Good Evening! In an application where I played the class diagram in visual studio by adding controller class, repository class, and service class, I encountered an error "The name 'ViewData' does not exist in the current context" in my HomeController. This is weird since the controller references System.Web.Mvc. The solution is: 1. Copy the source code in the HomeController and transfer it in a textfile for backup. 2. Delete the original HomeController. 3. Add another HomeController class 4. paste the backup code from the textfile. I guess this is a bug when using class diagrams in Visual Studio 2010. Greg

How To Get Textbox Or RichtextBox Value Using pInvoke In Windows API C#

Assuming you already get the pointer handle of the textbox/richtextbox control from source calling function, the snippet to get the content of the edit control is as follows. public const int GWL_ID = -12; public const int WM_GETTEXT = 0x000D; [DllImport("User32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int index); [DllImport("User32.dll")] public static extern IntPtr SendDlgItemMessage(IntPtr hWnd, int IDDlgItem, int uMsg, int nMaxCount, StringBuilder lpString); [DllImport("User32.dll")] public static extern IntPtr GetParent(IntPtr hWnd); private StringBuilder GetRichEditText(IntPtr hWndRichEdit) { Int32 dwID = GetWindowLong(hWndRichEdit, GWL_ID); IntPtr hWndParent = GetParent(hWndRichEdit); StringBuilder title = new StringBuilder(128); SendDlgItemMessage(hWndParent, dwID, WM_GETTEXT, 128, title); return title; } Greg

WPF Webbrowser Loop Through Html Elements And Submit

A question was raised on vbforums on how to invoke click a button using WPF webbrowser control. This sample loads google.com page and writes a sample text on the textbox and then invoking the click button. HTMLDocument document = (HTMLDocument)wbGetHost.Document; foreach (IHTMLElement myelem in document.getElementsByTagName( "input" )) { if (myelem.id != null ) { if (myelem.id.Equals( "lst-ib" ) && myelem.className.Equals( "lst lst-tbb" ) && !document.documentElement.innerHTML.ToLower().Contains( "wikipedia" )) { HTMLInputElement el = myelem as HTMLInputElement; el. value = "Bill Gates" ; HTMLInputElement searchButton = (HTMLInputElement)document.all.item( "btnK" , 0); searchButton.click(); break ; } } } Greg

The Controller For favicon.ico Does Not Implement IController

In an application using Controller factory, i encountered an error as stated in the title. My MVC does not have a favicon.ico. The solution is to add a parameter constraint that does not allow .ico filenames in your routes. I got the solution from forums.asp.net routes.MapRoute( "Default" , // Route name "{controller}/{action}/{id}" , // URL with parameters new { controller = "ProductView" , action = "Index" , id = "" }, // Parameter defaults new { controller = @"[^\.]*" } // Parameter constraints (regex/string expression) );

How To Count Duplicate Or Repeating Records From Union All Query In SQL

Here's a query to count number of repeating records based from union all query. Union all query does not remove duplicate records. Here's a sample script: select resultsduplicate.url as job_item, count (resultsduplicate.url) as repeat_occurence from ( SELECT url FROM mainTable where id = 47 and url like '%testsite.com%' and _active = 1 UNION ALL SELECT url FROM detailTable where id = 47 and url like '%testsite.com%' and _active = 1 )resultsduplicate group by resultsduplicate.url having ( count (resultsduplicate.url) >1); Original Source From (Stackoverflow.com)

Content Types Or MIME Types List In ASP.NET MVC

I have searched for content types which is suitable for ASP.NET or ASP.NET MVC applications using the HttpResponse class ContentType property. Here's the website with the MIME list: Mime Type List Here's a sample asp.net/mvc snippet. HttpResponseBase response = context.HttpContext.Response; response.ContentType = "application/pdf" ; Greg

WPF Controls Not Rendering Properly Or Correctly On Windows 7 OS

The problem was that the windows 7 theme was changed to classic window . Turning it back to Windows 7 default view, solved it. Greg

Check If Controls On another WPF Window Have Been Rendered Using Multithreading

Given you have two WPF windows namely MainWindow and OtherWindow. You basically want to check if the controls in main window have successfully loaded using statements in OtherWindow. The solution is to use Application dispatcher object. if (Application.Current.Dispatcher.CheckAccess()) { while ( true ) { foreach (Window window in Application.Current.Windows) { if (window.Title.Equals( "Project Title" )) { if (window.FindName( "your_control" ) != null ) { //do your stuff here... } } } break ; } } else { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(CheckMainWindow)); } Cheers!

Garbage Collection GC.Collect() Method In C# Slowing Web Crawlers Speed

In our web crawlers, we encountered slow crawling of items specially XML feeds. We checked our codes if there are lines generating bottlenecks. It turned out that we placed GC.Collect() in an inner loop that's processing item per item. The solution is to comment out GC.Collect() in the inner loop and transfer it to the outer loop statement. Here's the code: while (!EndOfPage) { do { if (date != String.empty) { //comment this statement, transfer outside inner loop... //GC.Collect(); //processing of items code statements... } } while (!(url.Equals(String.Empty))); GC.Collect(); PageNo++; if (PageNo > totalPage) { EndOfPage = true ; } } Credits to my fellow developer for the discovery. Greg

Regular Expression Match Capture Index Property Returns 0 Instead Of -1 In C#

Yesterday, while working on Regex Index property, I encountered a weird problem. Supposedly, string.indexOf(string variable) returns -1 value if there's no occurrence of such substring. However, using Regex.Match(source.ToLower(), @"regex pattern" ).Index returns 0 if instead of -1 if no such substring occurs. The solution was pointed out in stack overflow: Return index position of string after match found using Group.Success in which case returns a boolean value. So, here's the tip: if ((Regex.Matches(source.ToLower(), @"<ol[^>]*>" ).Count < 1) && (Regex.Matches(source.ToLower(), @"<ul[^>]*>" ).Count > 0)) { if (Regex.Match(source.ToLower(), @"<ul[^>]*>" , RegexOptions.IgnoreCase).Success) { // your if statements here.... :) } } Greg

Donate