How to send request from client to server printer for printing using c# .net windows application?
string schTime; string _lastTime; Timer timer1 = new Timer(); protected override void OnStart(string[] args) { try { //Debugger.Break(); TraceService("Start Service" + " " + DateTime.Now.ToString()); timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime); timer1.Enabled = true; //timer1.Interval = 1000; //string[] files = Directory.GetFiles(@"C:\PrintingDocument\"); //foreach (string file in files) //{ // if (File.Exists(file)) // { //timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime); //timer1.Enabled = true; // } // else // { // TraceService("File did not exists"); // } //} //Debugger.Break(); } catch (Exception ex) { TraceService("Error: " + ex); //EventLog.WriteEntry("Error: " + ex.Message); } } private void OnElapsedTime(object source, ElapsedEventArgs e) { try { //timer1.Stop(); //Debugger.Break(); //if (!schTime.Contains(DateTime.Now.ToString("HH:mm")) || DateTime.Now.ToString("HH:mm") == _lastTime) // return; //_lastTime = DateTime.Now.ToString("HH:mm"); timer1.Enabled = false; TraceService("Another entry at" + " " + DateTime.Now); if (!Directory.Exists(@"C:\PrintingDocument")) Directory.CreateDirectory(@"C:\PrintingDocument"); string[] files = Directory.GetFiles(@"c:\PrintingDocument\"); foreach (string file in files) { //if (string.IsNullOrEmpty(file)) //{ // //txtFileName.BackColor = Color.Yellow; // //MessageBox.Show("Please Select file."); // return; //} ProcessStartInfo info = new ProcessStartInfo(file); info.Verb = "Print"; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(info); TraceService(@"C:\PrintingDocument\" + file); TraceService(@"C:\PrintedDocument\" + file); System.IO.File.Move(@"C:\PrintingDocument\" + file, @"C:\PrintedDocument\" + file); } TraceService("Printing Sucessfully" + " " + DateTime.Now.ToString()); timer1.Enabled = true; //WindowsServiceSchedular(timer1); } catch (Exception ex) { EventLog.WriteEntry("Error: " + ex.Message); TraceService("Error: " + ex); } } private void TraceService(string content) { try { if (!Directory.Exists(@"C:\PrintingStatus")) Directory.CreateDirectory(@"C:\PrintingStatus"); FileStream fs = new FileStream(@"C:\PrintingStatus\PrintingStatus.Txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter sw = new StreamWriter(fs); sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(content); sw.Flush(); sw.Close(); } catch (Exception ex) { EventLog.WriteEntry("Error: " + ex.Message); } } protected override void OnStop() { timer1.Stop(); TraceService("Stop Service"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)