Buscar contenidos

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);
}