Monday, January 9, 2017
Logging in DotNetCore Application
Wednesday, December 28, 2016
Get FeatureLayer from GIS Layer Name in ArcGIS Explorer Application
FeatureLayer ToGoFeatureLayer = null;
foreach (MapItem EachMapItem in ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems)
{
if ((EachMapItem is FeatureLayer) && (EachMapItem.Name == GISLayerName))
{
ToGoFeatureLayer = (FeatureLayer)EachMapItem;
break;
}
}
return ToGoFeatureLayer;
}
XML Serialization in C#
Get all file info from the folder using C# code
Here is the code snippet to get all the file information from a folder in the descending order of creation date and time.
var dirInfo = new DirectoryInfo(folderNametoSearch);
FileInfo[] filesInfo = dirInfo.GetFiles().OrderByDescending(p => p.CreationTime).ToArray();
Get more details when an Error Exception is thrown in C#
All these exceptions can be handled properly and also logged. Using Reflection, we can get the class name and the function name which caused the exception
Simply use the following catch block in all your try-catch functions and pass all the exception to the Utility class to handle it.
catch (Exception ex)
{
MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();
string methodName = method.Name;
string className = method.ReflectedType.Name;
UtilClass.HandleError(className, methodName, ex);
}
Happy Coding !
Thursday, November 24, 2016
Download EXCEL file as a BLOB object in the client side
Here is the code snippet where the excel file object from the server can be downloaded as a blob at the client side.
XML to JSON tricks using C#.NET and Newtonsoft JSON Library
// Converting XML to JSON
Sunday, June 26, 2016
Find Distinct Column Values in C# DataTable
Here is the code snippet to find the Distinct Column Values from a C# DataTable.
DataView tempView = new DataView(tableInfo);
DataTable distinctValues = tempView.ToTable(true, "ColumnName");
Happy Coding !
Monday, May 30, 2016
Convert C# SQL Parameters list to C# DataTable
Here is the code snippet to convert C# SQL parameters list to C# DataTable.
Happy Coding.
private DataTable GetDataTableFromParamResults(List<SqlParameter> sqlParameterCollection)
{
DataTable paramResultsTable = new DataTable("ParamResultsTable");
foreach(SqlParameter eachParam in sqlParameterCollection)
{
DataColumn newCol = newDataColumn(eachParam.ParameterName.TrimStart(new char[] { '@' }), GetDBType( eachParam.DbType) );
paramResultsTable.Columns.Add(newCol);
}
DataRow newRow = paramResultsTable.NewRow();
foreach (SqlParameter eachParam in sqlParameterCollection)
{
string colName = eachParam.ParameterName.TrimStart(new char[] { '@' });
newRow[colName] = eachParam.Value;
}
paramResultsTable.Rows.Add(newRow);
return paramResultsTable;
}
private Type GetDBType(DbType inDbType)
{
Type togoType = null;
switch (inDbType)
{
case DbType.AnsiString:
togoType = Type.GetType("System.String");
break;
case DbType.Binary:
togoType = Type.GetType("System.Byte");
break;
case DbType.Byte:
togoType = Type.GetType("System.Byte");
break;
case DbType.Boolean:
togoType = Type.GetType("System.Boolean");
break;
case DbType.Currency:
togoType = Type.GetType("System.Decimal");
break;
case DbType.Date:
togoType = Type.GetType("System.DateTime");
break;
case DbType.DateTime:
togoType = Type.GetType("System.DateTime");
break;
case DbType.Decimal:
togoType = Type.GetType("System.Decimal");
break;
case DbType.Double:
togoType = Type.GetType("System.Double");
break;
case DbType.Guid:
togoType = Type.GetType("System.Guid");
break;
case DbType.Int16:
togoType = Type.GetType("System.Int16");
break;
case DbType.Int32:
togoType = Type.GetType("System.Int32");
break;
case DbType.Int64:
togoType = Type.GetType("System.Int64");
break;
case DbType.Object:
togoType = Type.GetType("System.Object");
break;
case DbType.SByte:
togoType = Type.GetType("System.SByte");
break;
case DbType.Single:
togoType = Type.GetType("System.Single");
break;
case DbType.String:
togoType = Type.GetType("System.String");
break;
case DbType.Time:
togoType = Type.GetType("System.DateTime");
break;
case DbType.UInt16:
togoType = Type.GetType("System.UInt16");
break;
case DbType.UInt32:
togoType = Type.GetType("System.UInt32");
break;
case DbType.UInt64:
togoType = Type.GetType("System.UInt64");
break;
case DbType.VarNumeric:
togoType = Type.GetType("System.Decimal");
break;
case DbType.AnsiStringFixedLength:
togoType = Type.GetType("System.String");
break;
case DbType.StringFixedLength:
togoType = Type.GetType("System.String");
break;
case DbType.Xml:
togoType = Type.GetType("System.String");
break;
case DbType.DateTime2:
togoType = Type.GetType("System.DateTime");
break;
case DbType.DateTimeOffset:
togoType = Type.GetType("System.DateTimeOffset");
break;
default:
throw new Exception("Unable to convert the type " + inDbType.ToString() +".");
}
return togoType;
}
All Blogs so far ...
-
►
2022
(1)
- ► March 2022 (1)
-
►
2021
(1)
- ► March 2021 (1)
-
►
2020
(1)
- ► October 2020 (1)
-
►
2019
(4)
- ► March 2019 (4)
-
►
2017
(7)
- ► November 2017 (5)
- ► February 2017 (1)
- ► January 2017 (1)
-
►
2016
(13)
- ► December 2016 (4)
- ► November 2016 (2)
- ► April 2016 (1)
- ► March 2016 (1)
- ► February 2016 (1)
- ► January 2016 (1)
-
►
2015
(12)
- ► December 2015 (1)
- ► November 2015 (1)
- ► October 2015 (1)
- ► September 2015 (1)
- ► August 2015 (1)
- ► April 2015 (1)
- ► March 2015 (1)
- ► February 2015 (1)
- ► January 2015 (1)
-
►
2014
(12)
- ► December 2014 (1)
- ► November 2014 (1)
- ► October 2014 (1)
- ► September 2014 (1)
- ► August 2014 (1)
- ► April 2014 (1)
- ► March 2014 (1)
- ► February 2014 (1)
- ► January 2014 (1)
-
►
2013
(12)
- ► December 2013 (1)
- ► November 2013 (1)
- ► October 2013 (1)
- ► September 2013 (1)
- ► August 2013 (1)
- ► April 2013 (1)
- ► March 2013 (1)
- ► February 2013 (1)
- ► January 2013 (1)
-
►
2012
(13)
- ► December 2012 (1)
- ► November 2012 (1)
- ► October 2012 (1)
- ► September 2012 (1)
- ► August 2012 (1)
- ► April 2012 (1)
- ► March 2012 (1)
- ► February 2012 (2)
- ► January 2012 (1)
-
►
2011
(16)
- ► December 2011 (1)
- ► November 2011 (3)
- ► October 2011 (1)
- ► September 2011 (1)
- ► August 2011 (1)
- ► April 2011 (2)
- ► March 2011 (1)
- ► February 2011 (2)
- ► January 2011 (1)
-
►
2010
(11)
- ► December 2010 (1)
- ► November 2010 (2)
- ► October 2010 (1)
- ► September 2010 (7)