Posts

Showing posts from March, 2012

Donate

How To Sort Dictionary<TKey,TValue> Object By Value Or By Key Using LINQ In C#

Here's a code I got from StackOverflow on how to sort dictionary object by value or by key using LINQ in C#. var sortedDict = ( from entry in SortedWebsiteNames orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); var sortedDict = ( from entry in SortedWebsiteNames orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

AutoComplete Winforms Search Not Working If Search Item Is One Character Digit In C#

Textbox properites: autocompletemode = append, autcompletesource = customsource. Assuming the autocompletestringcollection of the textbox are as follows: James Philipp Mariah Clara 8 Ryan GregEsguerra If you type the number 8 in the textbox, the textbox autocomplete does not suggest. As defined, it will search the prefix of the source. So, i guess one character does not have a prefix at all. The workaround for this is to add a space character after the digit 8. So, "8" becomes "8 ". Below is the code: private void PopulateWebsiteName() { try { if (dtWebsiteNames != null ) { dtWebsiteNames.Clear(); } dtWebsiteNames = JobsReporting.Scripts.GetWebsiteNamesLocal(); if (dtWebsiteNames.Rows.Count > 0) { foreach (DataRow row in dtWebsiteNames.Rows) { if (row[1].ToString().Trim().Length == 1) { row[1] = row[1]

ASP.NET Website Administration (Exception when adding users)

Upon registering new users, I encountered this error upon saving. An error was encountered. Please return to the previous page and try again. The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMeth

Simple Pager Template in ASP.NET Web Forms

Here's a simple pager template in ASP.NET Web Forms. < PagerTemplate > Page: <%= gvPRocess.PageIndex + 1%> of <%= gvPRocess.PageCount %> < asp:button ID = "btnFirst" runat = "server" CommandName = "Page" CommandArgument = "First" Text = "<<" /> < asp:button ID = "btnPrev" runat = "server" CommandName = "Page" CommandArgument = "Prev" Text = "<" /> < asp:button ID = "btnNext" runat = "server" CommandName = "Page" CommandArgument = "Next" Text = ">" /> < asp:button ID = "btnLast" runat = "server" CommandName = "Page" CommandArgument = "Last" Text = ">>" /> </ PagerTemplate >

How To Limit Or Reduce RAM Usage Of Mozilla Firefox Browser

Image
Hello, I noticed that Firefox takes a lot of RAM space on my workstation. After googling around, I found a solution on how to limit it's memory consumption. 1. Open Mozilla firefox 2. type about:config in the url/address bar 3. just click i'll be careful i promise 4. filter "browser.cache." 5. change browser.cache.disk.capacity from original value in my pc it's 1059997. I changed it to 30000 since my RAM space is 2GB. 6. Choose OK 7. Close and restart Mozilla firefox (I noticed the memory usage of firefox lowered to a significant level) Cheers! :=)

ASP.NET MVC (Add,Edit,Delete,View/View All) Example in C#

Image
Original Source: Developer Resources Just this evening, i modified an ASP.NET MVC example from Visual Basic.Net to C#. I also completed the steps and added some basic functionalities of my own. The database used is MS SQL Server 2008 and the data source is an ADO.NET Entity object. Below are the screenshots: Here is the snippet for the validation side in C#. This is not sophisticated: protected void ValidateEmployee(Employee EmployeeToValidate) { if (EmployeeToValidate.EmployeeName == null ) { ModelState.AddModelError( "EmployeeName" , "Employee name is required field." ); } if (EmployeeToValidate.Department == null ) { ModelState.AddModelError( "Department" , "Employee Department is required field." ); } if (EmployeeToValidate.EmployeeSalary == null ) { ModelState.AddModelError( "EmployeeSalary"

The remote server returned an error: (500) Internal Server Error (WebCclient) In C#

In our case when we encountered this error using WebClient, the solution was to set the user agent and add it as header to the WebCclient object. newWebClient.Headers.Add( "user-agent" , "Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0" );

SET Variable (User Defined) In MySQL Returns NULL (MySQL Browser)

Source: MySQL bug Forum Steps 1. Open MySQL Browser 2. Click Tools menu 3. Click Options 4. Choose Browser 5. Check Show Advanced Toolbars 6. Click Apply 7. Click close 8. Transactions Toolbar appears on MySQL Browser 9. Click the Transaction button on the transaction toolbar everytime you execute the query Sample query: Set @ names = 'james' ; select @ names ;

How To Get Or Retrieve The Response URL From WebRequest Object Using C#

The solution is to get the ResponseUri from the response object. //domain url: http://www.htcatalogs.com.au //response url: http://www.htcatalogs.com.au/2012/dailylistings/ WebRequest request = WebRequest.Create( "http://www.rmwilliams.com.au" ); HttpWebResponse resp = HttpWebResponse)request.GetResponse(); string ur = resp.ResponseUri.ToString(); Console.Write(ur);

Add Reference To WPF Merged Resource Dictionary In Window.xaml

Good evening guys! Here's how to add reference to WPF Merged Dictionary in Window.xaml. <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <!--resource dictionary is placed in folder--> <ResourceDictionary Source= "/ResourceDictionaries/RoundedButton.xaml" /> <!--dictionary is inside WPF project--> <!--<ResourceDictionary Source="RoundedButton.xaml" /> --> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources>

Download File Using Webrequest With Credentials In C#

Here's a C# code that will download a file from source with credentials (password and username). This assumes that the source directory is password protected. HttpWebRequest request; HttpWebResponse response = null ; try { string username = "xxxuser" ; string password = "yyypass" ; NetworkCredential myCredentials = new NetworkCredential(username, password); request = (HttpWebRequest)WebRequest.Create(ListURL); request.Timeout = 900000000; request.Credentials = myCredentials; request.AllowWriteStreamBuffering = false ; response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); //Write to disk FileStream fs = new FileStream( "\\192.168.3.3\xmldata.xml" , FileMode.Create); byte []

Enable Saving Of Changes That Require Table To Be Re-Created

Source: SQL Server Central The solutions is: 1. Go to Tools on MS SQL IDE 2. Click Options 3. Then Designers 4. Then Table and Database Designers 5. Uncheck Prevent saving changes that require table re-creation.

Donate