Tuesday, September 23, 2014

jQuery selectors select 2nd cell of 2nd row of 2nd table


 

     
       
         X
         **some text that changes**
         **ssss**
     
 

Jquery:

$(function(){
   var text = $("table:eq(1) tr:eq(1) td:eq(2)").text();
   alert(text);
});

Monday, August 25, 2014

Save Error Log or Exception Log in text file in C#

Add a class file name it as ErrorLog
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Text;
using System.IO;

namespace Save_Error_Log_or_Exception
{
    public class ErrorLog
    {
        public bool WriteErrorLog(string LogMessage)
        {
            bool Status = false;
            string LogDirectory = ConfigurationManager.AppSettings["LogDirectory"].ToString();

            DateTime CurrentDateTime = DateTime.Now;
            string CurrentDateTimeString = CurrentDateTime.ToString();
            CheckCreateLogDirectory(LogDirectory);
            string logLine = BuildLogLine(CurrentDateTime, LogMessage);
            LogDirectory = (LogDirectory + "Log_" + LogFileName(DateTime.Now) + ".txt");

            lock (typeof(ErrorLog))
            {
                StreamWriter oStreamWriter = null;
               try
               {
                   oStreamWriter = new StreamWriter(LogDirectory, true);
                    oStreamWriter.WriteLine(logLine);
                    Status = true;
                }
               catch
              {

               }
                finally
                {
                    if (oStreamWriter != null)
                    {
                        oStreamWriter.Close();
                    }
                }
            }
            return Status;
        }

        private bool CheckCreateLogDirectory(string LogPath)
        {
            bool loggingDirectoryExists = false;
            DirectoryInfo oDirectoryInfo = new DirectoryInfo(LogPath);
            if (oDirectoryInfo.Exists)
            {
                loggingDirectoryExists = true;
            }
            else
            {
                try
                {
                    Directory.CreateDirectory(LogPath);
                    loggingDirectoryExists = true;
                }
                catch
                {
                    // Logging failure
                }
            }
            return loggingDirectoryExists;
        }

        private string BuildLogLine(DateTime CurrentDateTime, string LogMessage)
        {
            StringBuilder loglineStringBuilder = new StringBuilder();
            loglineStringBuilder.Append(LogFileEntryDateTime(CurrentDateTime));
            loglineStringBuilder.Append(" \t");
            loglineStringBuilder.Append(LogMessage);
            return loglineStringBuilder.ToString();
        }


        public string LogFileEntryDateTime(DateTime CurrentDateTime)
        {
            return CurrentDateTime.ToString("dd-MM-yyyy HH:mm:ss");
        }


        private string LogFileName(DateTime CurrentDateTime)
        {
            return CurrentDateTime.ToString("dd_MM_yyyy HH:mm:ss");
        }
    }
}
------------
Page_Load:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Save_Error_Log_or_Exception
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            ErrorLog oErrorLog = new ErrorLog();
            try
            {
                int i,j,k;

                i = 100;
                j = 0;
                k =i/j;

               

            }
            catch (Exception ex)
            {
                oErrorLog.WriteErrorLog(ex.ToString());
               
               
            }
        }
    }
}

Thursday, July 10, 2014

How to Find Grid Rows Length In Jquery





var rowCount = $('#grdpayments').find('tr').length;

Wednesday, February 12, 2014

reverse of a string in c#.net

senario: 1


string res = "";
            string sa = "";
            string s = "hyd is good";

            for (int i = s.Length - 1; i = 0; i--)
            {

                res = res + s[i];
            }

Output:  "doog si dyh"







senario: 2







            string[] arr = s.Split(' ');

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                sa += arr[i] + " ";
            }

Output:  "good ishyd"





senario: 3

  string[] arr = s.Split(' ');

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                sa += arr[i] + " ";
            }

            for (int i = 0; i < arr.Length; i++)
            {
                string ss = arr[i];

                for (int j = ss.Length - 1; j >= 0; j--)
                {
                    res += ss[j];
                }
                res += " ";
            }

Output:  "dyh si doog"


 senario: 4


  public static string RecursivelyReverseString(string s)
        {
            if (s.Length > 0)
                return s[s.Length - 1] + RecursivelyReverseString(s.Substring(0, s.Length - 1));
            else
                return s;
        }

Output:  "doog si dyh"

Thursday, January 23, 2014

Action Filters in MVC

 1)OutputCache  Filters in MVC:

Controler:

[OutputCache(Duration = 10)]
        public ActionResult test()
        {
            ViewBag.Date = DateTime.Now.ToString("T");
           
            return View();
        }

View:
@{
    ViewBag.Title = "test";
    @ViewBag.Date;
}

test

Monday, January 13, 2014

What is An ActionFilters in MVC..?

Sometimes you want to perform logic either before an action method is called or after an action method runs. To support this, ASP.NET MVC provides filters. Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behavior to controller action methods.



ASP.NET MVC supports the following types of action filters:
What are the Types of Action Filters ?


Types of Action Filters

  • Authorization filters. These implement IAuthorizationFilter and make security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. The AuthorizeAttribute class and the RequireHttpsAttribute class are examples of an authorization filter. Authorization filters run before any other filter.
  •  

How to Create a Custom Action Filter for MVC 3 ?

http://sampathloku.blogspot.in/2013/03/how-to-create-custom-action-filter-for.html