Monday, April 1, 2013

Get OS version in C# the easy way

Leave a Comment
c# os version

Hi, today im going to show you the easy way to get the OS version in C#. So Fire up Visual Studio and select new Console application project and Name in GetOSVersion.


  •  Add a reference to Microsoft.VisualBasic assembly.
  • Add Namespace
    //Import Namespace
    using Microsoft.VisualBasic.Devices;
  • Add below code in program class
            static void Main(string[] args)
            {
                //Create a new instance of computer class
                Computer com = new Computer();
                Console.WriteLine("OS Name: " + com.Info.OSFullName);
                Console.WriteLine("OS Version: " + com.Info.OSVersion);
                Console.WriteLine("OS Platform: " + com.Info.OSPlatform);
                Console.ReadLine();
             }
    
    
  • Done. :)

Below is full code of program class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Import Namespace
using Microsoft.VisualBasic.Devices;
namespace GetOSVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new instance of computer class
            Computer com = new Computer();
            Console.WriteLine("OS Name: " + com.Info.OSFullName);
            Console.WriteLine("OS Version: " + com.Info.OSVersion);
            Console.WriteLine("OS Platform: " + com.Info.OSPlatform);
            Console.ReadLine();
        }
    }
}

Hope you like this method.

Read More...

Thursday, March 28, 2013

Hack any site with Javascript

Leave a Comment
Here is JAVASCRIPT with it you can hack any SITES. with some sites it may not work. the code is just for fun it does not harm any site as it just work on clients browser.



Here is the Code:
javascript:document.contentEditable=true;document.designMode='on';void 0; 
Type or just copy paste on the browsers address bar. watch the video in high quality for details.

Please Note: its Just a Fun script, its not a script with which you can hack any sites passwords.

Read More...

Compare DataTables with LINQ and C#

8 comments



Hi Friends, There are times when we want to compare two DataTables and find out the Differences in them. There are different ways of doing it, The Most common way is by using Loops but the problem of using loops is that, if records are more in both Tables then loops execution time increases which can be performance killer.

Here i would like to show a method which can be used to compare both Datatables and list there Differences. This method is short and sweet and uses LINQ for comparing the results.

So to Start, first fire up Visual Studio, select New Console Application Project and name it as "CompareDataTable", Make sure you select .Net Framework 3.5 as Linq was introduced in it.

In below example we are creating two DataTables dt1 and dt2 and pass them to our method "CompareDataTables" to compare them.


 static void Main(string[] args)
        static void Main(string[] args)
        {
            //Declare Datatables dt1 and dt2
            DataTable dt1 = new DataTable(),dt2 = new DataTable();
            //Add columns and datatypes for datatable dt1
            dt1.Columns.Add("Id",typeof(int));
            dt1.Columns.Add("Name", typeof(string));
            dt1.Columns.Add("Address", typeof(string));
            //Add columns and datatypes for datatable dt2
            dt2.Columns.Add("Id", typeof(int));
            dt2.Columns.Add("Name", typeof(string));
            dt2.Columns.Add("Address", typeof(string));
            //Add rows for datatable dt1
            dt1.Rows.Add(1, "Hardcoderz", "ABC");
            dt1.Rows.Add(1, "G Gurav", "ABC2");
            dt1.Rows.Add(1, "Ganesh Gurav", "ABC1");
            //Add rows for datatable dt2
            dt2.Rows.Add(1, "Hardcoderz", "ABC");
            dt2.Rows.Add(1, "D Gurav", "ABC2");
            dt2.Rows.Add(1, "Ganesh Gurav", "ABC1");
            //Call our CompareDataTables() Method
            CompareDataTables(dt1, dt2);

        }

So lets write our CompareDataTables method. The method will fetch non matching rows by using Except Method of linq and store it in NoMatch1 variable. Records1 and Recodrs2 are AnonymousType of Linq. Below code illustrates it.
static void CompareDataTables(DataTable dt1, DataTable dt2)
        { 
   var Records1 = dt1.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(),Address = s1["Address"].ToString() });
  var Records2 = dt2.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(), Address = s1["Address"].ToString() });
  var NoMatch1 = Records1.Except(Records2);
 }
Now Making our Method more descriptive. Our Method CompareDataTables Convert the Datatables to a collection of AnonymousType, and fetches the non matching values by Linq Except method. and Prints the result on the screen.

static void CompareDataTables(DataTable dt1, DataTable dt2)
        {
            // All data in both DataTables are stored in Records1 and Records2 of type Anonymous, as we dont know the Type we use var. 
            var Records1 = dt1.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(),Address = s1["Address"].ToString() });
            var Records2 = dt2.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(), Address = s1["Address"].ToString() });
            //show values of dt1 stored in Records1 Anonymous Type
            Console.WriteLine("Table 1:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            // Select is a Linq method to fetch data from collections.
            //ToArray<string>() is used to create a array of string.
            //Join is use to Join array of string with new line (\n).
            Console.WriteLine(string.Join("\n", Records1.Select(s1 => Convert.ToString(s1.Id) + " | " + Convert.ToString(s1.Name) + " | " + Convert.ToString(s1.Address)).ToArray>string>()));
            Console.WriteLine("\nTable 2:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            // Select is a Linq method to fetch data from collections.
            //ToArray<string>() is used to create a array of string.
            //Join is use to Join array of string with new line (\n).
            Console.WriteLine(string.Join("\n", Records2.Select(s1 => Convert.ToString(s1.Id) + " | " + Convert.ToString(s1.Name) + " | " + Convert.ToString(s1.Address)).ToArray<string>()));
            //Except method of Linq returns non match rows.
            var NoMatch1 = Records1.Except(Records2);
            var NoMatch2 = Records2.Except(Records1);
            //Show Non matching records from table 1.
            Console.WriteLine("\nNon Matching Records: From Table 1:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            Console.WriteLine(string.Join("\n", NoMatch1.Select(s1 => Convert.ToString(s1.Id) + " " + Convert.ToString(s1.Name) + " " + Convert.ToString(s1.Address)).ToArray<string>()));
            //show non matching records from table 2
            Console.WriteLine("\nNon Matching Records: From Table 2:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            Console.WriteLine(string.Join("\n", NoMatch2.Select(s1 => Convert.ToString(s1.Id) + " " + Convert.ToString(s1.Name) + " " + Convert.ToString(s1.Address)).ToArray<string>()));
            Console.ReadLine();
        }
The Full code of Program.cs is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web.UI.WebControls;

namespace CompareDataTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Declare Datatables dt1 and dt2
            DataTable dt1 = new DataTable(),dt2 = new DataTable();
            //Add columns and datatypes for datatable dt1
            dt1.Columns.Add("Id",typeof(int));
            dt1.Columns.Add("Name", typeof(string));
            dt1.Columns.Add("Address", typeof(string));
            //Add columns and datatypes for datatable dt2
            dt2.Columns.Add("Id", typeof(int));
            dt2.Columns.Add("Name", typeof(string));
            dt2.Columns.Add("Address", typeof(string));
            //Add rows for datatable dt1
            dt1.Rows.Add(1, "Hardcoderz", "ABC");
            dt1.Rows.Add(1, "G Gurav", "ABC2");
            dt1.Rows.Add(1, "Ganesh Gurav", "ABC1");
            //Add rows for datatable dt2
            dt2.Rows.Add(1, "Hardcoderz", "ABC");
            dt2.Rows.Add(1, "D Gurav", "ABC2");
            dt2.Rows.Add(1, "Ganesh Gurav", "ABC1");
            //Call our CompareDataTables() Method
            CompareDataTables(dt1, dt2);

        }
        static void CompareDataTables(DataTable dt1, DataTable dt2)
        {
            // All data in both DataTables are stored in Records1 and Records2 of type Anonymous, as we dont know the Type we use var. 
            var Records1 = dt1.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(),Address = s1["Address"].ToString() });
            var Records2 = dt2.AsEnumerable().Select(s1 => new { Id = s1["Id"].ToString(), Name = s1["Name"].ToString(), Address = s1["Address"].ToString() });
            //show values of dt1 stored in Records1 Anonymous Type
            Console.WriteLine("Table 1:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            // Select is a Linq method to fetch data from collections.
            //ToArray<string>() is used to create a array of string.
            //Join is use to Join array of string with new line (\n).
            Console.WriteLine(string.Join("\n", Records1.Select(s1 => Convert.ToString(s1.Id) + " | " + Convert.ToString(s1.Name) + " | " + Convert.ToString(s1.Address)).ToArray<string>()));
            Console.WriteLine("\nTable 2:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            // Select is a Linq method to fetch data from collections.
            //ToArray<string>() is used to create a array of string.
            //Join is use to Join array of string with new line (\n).
            Console.WriteLine(string.Join("\n", Records2.Select(s1 => Convert.ToString(s1.Id) + " | " + Convert.ToString(s1.Name) + " | " + Convert.ToString(s1.Address)).ToArray<string>()));
            //Except method of Linq returns non match rows.
            var NoMatch1 = Records1.Except(Records2);
            var NoMatch2 = Records2.Except(Records1);
            //Show Non matching records from table 1.
            Console.WriteLine("\nNon Matching Records: From Table 1:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            Console.WriteLine(string.Join("\n", NoMatch1.Select(s1 => Convert.ToString(s1.Id) + " " + Convert.ToString(s1.Name) + " " + Convert.ToString(s1.Address)).ToArray<string>()));
            //show non matching records from table 2
            Console.WriteLine("\nNon Matching Records: From Table 2:");
            Console.WriteLine("--------------------");
            Console.WriteLine("Id | Name | Address");
            Console.WriteLine("--------------------");
            Console.WriteLine(string.Join("\n", NoMatch2.Select(s1 => Convert.ToString(s1.Id) + " " + Convert.ToString(s1.Name) + " " + Convert.ToString(s1.Address)).ToArray<string>()));
            Console.ReadLine();
        }

    }
}
Note: There may be other more easy ways to do this, even there may be situation were this method may not provide expected results. I showed this method cause this method resolved my problem of comparing two Datatables with small code and without using Loops.

Read More...

Wednesday, March 20, 2013

Facebook/Gmail Style ASP.NET JQuery Ajax Chat Control

90 comments

Like my Chat Control? Rate it at HotScripts > Hot Scripts


























ASP.NET Jquery Ajax Chat Control / DG2 Chat Control 


This is the control on which i have spend nearly 4 months from my busy schedule. Hope those who need this will like it.
Releasing the Control in its first Beta Version.

ASP.NET Jquery Ajax Chat Control is built on .Net Framework 3.5. It uses Jquery 1.8 library and Jquery UI 1.9 library.
Tested to work on IE7+, Google Chrome, Firefox, Safari.

Features:

  • Easy to Integrate as its a Control just drag and drop and provide necessary settings.
  • Good Looks, Lots of Themes, even custom Themes can be designed as it uses JQuery UI for Theming.
  • MS SQL and MySQL Database support
  • Rich Ajax Interface.
  • Avatar / Picture Support.
  • Profile Link Support.
  • Search Users.
  • Animated Smileys.
  • Animated User Typing Notification.
  • Three Status modes Invisible,Offline and Online.
  • Visual Notification.
  • Alert Notification.
  • Error Notification.
  • Good Response Time.
  • and much more.......

Like my Chat Control? Rate it at HotScripts > Hot Scripts

Demo:
  • Try to Open Below Links in different Browsers. Unexpected result may occur due to usage by different users trying the demo.
  • Demo1
  • Demo2
  • Demo3
Download:
  • DG.Square.AjaxChat.Control v1.1
  • DG.Square.AjaxChat.Control v1.0
  • Update 5th Dec 2013
  • Currently disabled as new version development is in progress.
  • I have stopped this project since May 2013 but due to lots of emails and 100+ comments pending for approval i have decided to release version 2.0.
  • Version 2.0 will be released in Mid or last week of December 2013.

Update 24 Mar 2013:

For  those who are able to run this in local host but not on webserver, try to add below code in your web.config file.

<add name="DG2AjaxChat" path="*.ajaxchat" verb="*" type="DG.Square.ASP.NET.Ajax.ChatControl.AjaxHandler" />

under this:
<system.webServer>
<handlers>

</handlers>
</system.webServer>

you can check my sample projects webconfig files <system.webServer><handlers> tag


Update 21 Apr 2013:


  • v1.1 Released.
  • Please check sample projects connection string section in web.config file for mysql connection string.
  • connection string should have providername.
  • Let me know of any queries here or you can email me. my email id can be found from my profile page.


Changelog:

v 1.1
  • added support for jquery multiple versions compatibility.
  • added MySQL Database support.
  • added Auto logout if user don't logout.
  • Added support for InProc, StateServer and SqlStateServer Session Mode.
  • now compatible with .Net framework 2.0.
  • added new Theme "DGTheme".
v1.0
  • Initial Release.


Final Notes:

Next Version will include Bug fixes reported or found.
Let me know any Queries or Report Bugs with screenshot and details. Have a Nice Time. :)




Like my Chat Control? Rate it at HotScripts > Hot Scripts

Read More...

Wednesday, June 13, 2012

Asp.Net version of Anant Garg Gmail/Facebook Style (PHP) jQuery Chat

Update 20th Mar 2013: New Chat Control Launched check here.


For all those who have been waiting for Asp.Net version of  Anant Garg's Gmail/Facebook Style jQuery Chat is  now over.
i have converted it to asp.net from php.

I No longer Have this Source code, it got lost in hard disk failure.


Launched the New Chat Control, check link below:





Download: 
DG.Square ASP.NET AjaxChat Control

Read More...

Enable / Disable / Write Protect USB in Windows with .NET

Leave a Comment

In this article i will provide you a tool with source code to control USB devices.
you can Enable/Disable/Write Protect USB devices with this tool.
The Tool is made in VB.NET.
I used VS 2010 to create this software.
Hope you will like it.
Download Link: (Source +  Demo exe)
Download Here

Read More...