Thursday 27 June 2013

Store Datatable Column Name in an Array Using LINQ

If you want to store datatable column values in an array using LINQ you can achieve this by the following ways.

string[] ColName = dt.Columns.Cast<DataColumn>().
                                   Select(x => x.ColumnName).ToArray();

Wednesday 26 June 2013

Store Datatable Row Values in Jagged Array using LINQ

If you want to store values of a datatable in a jagged array using LINQ you can achieve in the following ways.

string[][] Value = dt.Rows.OfType<DataRow>().
                                Select(r => dt.Columns.OfType<DataColumn>().
                                Select( c => r[c.ColumnName].ToString()).ToArray()).
                           ToArray();

Thursday 6 June 2013

Find System MAC Address using C#

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(GetMACAddress());
}

public string GetMACAddress()
{
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();        
        foreach (NetworkInterface adapter in nics)
        {
             if (sMacAddress == String.Empty)  // only return MAC Address from first card  
             {
                   IPInterfaceProperties properties = adapter.GetIPProperties();
                   return adapter.GetPhysicalAddress().ToString();
              }
        }
        return String.Empty;
}

Saturday 1 June 2013

WCF Service Host cannot find any service metadata. This may cause the client application to run improperly. Please check if metadata is enabled. Do you want to exit?

In my case I got this error because the service name field did not actually match the namespace of the class actually implementing the operation contract in app.config file.

<services>
<service name="WCFHelloWorld.MySyncService" behaviorConfiguration="WCFHelloWorld.Service1Behavior">
.
.
.
</services>