arşiv

Cuma, 26 May 2017 için arşiv

C# Caller Information

Cuma, 26 May 2017 yorum yok
namespace CallerInfo
{
    public class CallerInfoExample
    {
        public void Log(String logMessage, [CallerMemberName] string callerName="", 
                                           [CallerLineNumber] int lineNumber=0, 
                                           [CallerFilePath] string filePath="")
        {
            Console.WriteLine("Çağrıldığı Dosya=" + filePath);   
            Console.WriteLine("Çağıran Metod="+callerName);
            Console.WriteLine("Çağrıldığı Satır Numarası=" + lineNumber); 
        }        
    }
}

namespace CallerInfo
{
    class Test
    {
        static void Main()
        {
            CallerInfoExample callerInfo = new CallerInfoExample();
            callerInfo.Log("Caller Info Test");
        }
    }
}

 

Categories: C# Tags:

Export To Excell Helper

Cuma, 26 May 2017 yorum yok
public static void GridExportToExcel(string fileName, object dataTable)
{
    var grid = new GridView();
    grid.DataSource = dataTable;
    grid.DataBind();

    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}-{1}.xls", fileName, DateTime.Now.ToShortDateString().Replace(".", "")));
    HttpContext.Current.Response.ContentType = "application/ms-excel";
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
    HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    grid.RenderControl(htw);

    HttpContext.Current.Response.Write(sw.ToString());
    HttpContext.Current.Response.End();
}

 

Categories: Genel Tags: