Buscar contenidos

lunes, 22 de enero de 2018

Error + GlobalAsax + Application_Error



  protected void Application_Error(object sender, EventArgs e)
        {   

string HtmlErrorHandling = @"
            <html>
               <head>
                  <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
                  <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
                  <link rel='stylesheet' type='text/css' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
                  <script type='text/javascript'>
                     $(function() {
        
                     $('#DetalleContent').hide();
                 
                     $('#VerDetalle').click(function() {
        
                     $('#DetalleContent').slideToggle();
        
                     });
        
                     });
        
                  </script>
               </head>
               <body style='font-family: Helvetica, Arial, sans-serif; font-size: 14px;'>
                  <div class='row'>
                     <div class='col-sm-3'>&nbsp;</div>
                     <div class='col-sm-6'>
                        <img alt='' class='img-responsive' src='/Images/ErrorImage.png' />
                     </div>
                     <div class='col-sm-3'>&nbsp;</div>
                  </div>
                  <hr style='border:10px solid #D8D8D8;'/>
                  <div class='row'>
                     <div class='col-sm-12' style='font-size:15px; cursor: pointer; color:#BE2021; text-align: center;' ><a href='[uri]'>Clic aquí para reintentar ingresar</a></div><hr/>
                     <div id='VerDetalle' class='col-sm-12' style='font-size:13px; cursor: pointer; color:#BE2021; text-align: center;' >Clic aquí para ver detalle técnico</div>
                     <div id='DetalleContent' class='col-sm-12' style='font-size:12px; color:#B2A9A7; text-align: center;' >[error]</div>
                  </div>
               </body>
            </html>
            ";
         
            string ErrorContent = "<b>Message:</b><br/>" + CurrentError.Message + "<br/>" + "<b>StackTrace:</b><br/>" + CurrentError.StackTrace + "<br/>" + "<b>InnerException:</b><br>" + CurrentError.InnerException + "<br/>" + "<b>Source:</b><br/>" + CurrentError.Source;

            HtmlErrorHandling = HtmlErrorHandling.Replace("[error]", ErrorContent).Replace("[uri]", Request.Url.AbsoluteUri);

            HttpContext.Current.Response.ContentType = "text/html";
            Response.Write(HtmlErrorHandling);

            Server.ClearError();

viernes, 15 de diciembre de 2017

c# Escribir en EventLog

  static string EventLogName = "Name";

        private static bool CheckSourceExists(string source)
        {
            if (EventLog.SourceExists(source))
            {
                EventLog evLog = new EventLog { Source = source };

                if (evLog.Log != EventLogName)
                {
                    EventLog.DeleteEventSource(source);
                }
            }

            if (!EventLog.SourceExists(source))
            {
                EventLog.CreateEventSource(source, EventLogName);

                EventLog.WriteEntry(source, String.Format("Event Log Created '{0}'/'{1}'", EventLogName, source), EventLogEntryType.Information);
            }

            return EventLog.SourceExists(source);
        }

        private static void WriteEventToMyLog(string source, string text, EventLogEntryType type)
        {
            if (CheckSourceExists(source))
            {
                EventLog.WriteEntry(source, text, type);
            }
        }

      

lunes, 11 de diciembre de 2017

C# Imprimir PDF a una impresora en específico




string a = System.Environment.MachineName;

Process proc = new Process();
//"C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe"
proc.StartInfo.FileName = adobePath;

//FilePath: c://test.pdf
proc.StartInfo.Arguments = @" /t /h " + "\"" + FilePath + "\"" + " " + "\"" + "Bullzip PDF Printer" + "\"";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
Thread.Sleep(1000);
proc.WaitForInputIdle();




public static List<string> GetPrinterList()
{
    List<string> l = new List<string>();

    foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    {
        l.Add(printer);
    }

    return l;
}

public static string GetDefaultPrinter()
{
    PrinterSettings settings = new PrinterSettings();

    return (settings.PrinterName);
}