Friday, November 3, 2017

Continue loop iteration after exception is thrown

One of my friend working on one project which has task and task has for loop inside.

Like this,

try
{
    foreach (var item in collection)
    {
        if (item == null)
        {
            throw new Exception("item {0} is null" + item);
        }
    }
}
catch (Exception ex)
{
    WriteLog.AppendLine(ex.Message);
}

but loop was exited when any exception was occur, but what he want if any exception comes just leave that records, log the exception and countinue the loop.

Was what i suggested is "Use try and Catch block inside the loop", so that if any error comes while processing item, then it will log the exception and continue the loop.

foreach (var item in collection)
{
    try
      {
           if (item == null)
           {
              throw new Exception("item {0} is null" + item);
           }
      }
    catch (Exception ex)
      {
          WriteLog.AppendLine(ex.Message);
      }
}


Thursday, November 2, 2017

Set Span value using Jquery

Using jQuery to set value on SPAN element

Let say we have below span element,
<Span id="spnTest" class="red"></span>
You can set value of span element using two ways,

1) By Using Class name of Span
$(".red").text("Hello");

$(".red").html("Hello");

2) By Using Id of Span
$("#spnTest").text("Hello");

$("#spnTest").html("Hello");

stringbuilder clear

How to Clear stringbuilder string.

StringBuilder stringBuilder = new StringBuilder();

Just use Clear method on stringbuilder object to clear stringbuilder content.

stringbuilder.Clear();

Wednesday, October 25, 2017

Change line height in Kendo UI Web editor

Change line height in Kendo UI Web editor

We can do it by configuring the stylesheet property of the editor, and then configuring the tools that will apply the styles to the selected content.
$("#editor").kendoEditor({
  tools: [
    { name: "formatting", items: [
      { text: "Error", value: ".Error" },
      { text: "OK", value: ".OK" },
      { text: "Inline Code", value: ".inCode" }
    ] }
  ],
  stylesheets: [
    "../../content/web/editor/editorStyles.css"
  ]
});

Wednesday, October 11, 2017

line height CSS

What is Line Height in CSS?


- Line Height property defines amount of height in which text content is written in HTML.

Properties of Line Height:

Normal: 

This is default Height line, generally around 100% to 120%. 

e.g.: Default Height line in word document.

Number:

A number that will be multiplied with the current font size to set the line height.

Length:

 Fixed Length in px, pt etc.

Percentage: 

% of current font size.

Initial:

Set to default value.

Inherit:

Inherit from Parent.

Please find the example below for more detail,

HTML





Output


normal line height.
normal line height.
percentage line height.
percentage line height.
length line height.
length line height.

Sunday, October 8, 2017

Application's path in a .NET console application

How can I get the application's path in a .NET console application? OR Get path for my assembly.

System.Reflection.Assembly.GetEntryAssembly().Location;

Thursday, October 5, 2017

Using Replace in Update statement SQL

Using Replace in Update statement SQL

Suppose you have following table 'MasterData' table in SQL,


You want to replace '!!' by '{{' and '||' by '}}' in data column of table. How would you do it.

=> You can do it by using Replace function in Update statement of SQL Server as below,


UPDATE dbo.MasterData
SET Value = REPLACE(REPLACE(Data, '!!', '{{'),'||','}}')

WHERE ID = 1

Inner Replace function is used for replacing '!!' characters and outer replace function is used to replace  '||'.