2009-04-25 4 views
2

Nun, meine Situation ist wie folgt:DOS basierter Druck durch ASP.NET

ich auf dem Server einen Bericht als Textdatei bin zu erzeugen, die auf einem Punktmatrixdrucker mit DOS-Modus werden muss gedruckt. Ich möchte Windows drucken vermeiden, weil es zu langsam wäre. Gibt es einen Weg in ASP.NET, über den ich DOS-basiertes Drucken durchführen kann, wie es für Nadeldrucker am besten geeignet ist. Ich habe das Netz durchforstet, konnte aber keine Lösung oder Hinweise finden. Hat irgendein Körper irgendwelche Hinweise/Lösungen, die er implementiert oder über die er gestolpert ist?

Diese Anwendung ist eine webbasierte Anwendung.

Danke.

+1

Möchten Sie vom Server oder vom Client drucken? Damit meine ich, dass Sie auf einem Drucker drucken möchten, der auf dem Webserver oder auf der Client-Seite installiert ist? Für die erstere, erstellen Sie einfach eine separate exe/Batch-Datei und lassen Sie die ASP.NET-App das ausführen, und für den letzteren benötigen Sie eine Art von ActiveX, um dies zu erreichen. – BobbyShaftoe

+0

Wie kann ich die ASP.nET-Anwendung ausführen, an der ich interessiert bin? – Codeslayer

Antwort

4

Wenn ich Sie richtig verstehe, besteht eine Möglichkeit darin, eine Batch-Datei auszuführen, die den tatsächlichen Druck von ASP.NET ausführen würde. Von here:

// Get the full file path 
string strFilePath = “c:\\temp\\test.bat”; 

// Create the ProcessInfo object 
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe"); 
psi.UseShellExecute = false; 
psi.RedirectStandardOutput = true; 
psi.RedirectStandardInput = true; 
psi.RedirectStandardError = true; 
psi.WorkingDirectory = “c:\\temp\\“; 

// Start the process 
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi); 


// Open the batch file for reading 
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); 

// Attach the output for reading 
System.IO.StreamReader sOut = proc.StandardOutput; 

// Attach the in for writing 
System.IO.StreamWriter sIn = proc.StandardInput; 


// Write each line of the batch file to standard input 
while(strm.Peek() != -1) 
{ 
    sIn.WriteLine(strm.ReadLine()); 
} 

strm.Close(); 

// Exit CMD.EXE 
string stEchoFmt = "# {0} run successfully. Exiting"; 

sIn.WriteLine(String.Format(stEchoFmt, strFilePath)); 
sIn.WriteLine("EXIT"); 

// Close the process 
proc.Close(); 

// Read the sOut to a string. 
string results = sOut.ReadToEnd().Trim(); 


// Close the io Streams; 
sIn.Close(); 
sOut.Close(); 


// Write out the results. 
string fmtStdOut = "<font face=courier size=0>{0}</font>"; 
this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine, "<br>"))); 
+0

das ist ein paar ernsthafte Hacking, du hast dort angefangen Mann! Gut gemacht. Ich hätte es in eine Warteschlange geworfen und später herausgefunden, was damit zu tun ist. lol –

0

Die Antwort von BobbyShaftoe korrekt ist (Natürlich können Sie einige der Code schreiben die Ausgabe auf der Seite weglassen). Hier ist eine pedantische Version davon:

public static void CreateProcess(string strFilePath) 
{ 
    // Create the ProcessInfo object 
    var psi = new ProcessStartInfo("cmd.exe") 
        { 
         UseShellExecute = false, 
         RedirectStandardOutput = true, 
         RedirectStandardInput = true, 
         RedirectStandardError = true, 
         WorkingDirectory = "c:\\temp\\" 
        }; 

    // Start the process 
    using (var proc = Process.Start(psi)) 
    { 
     // Attach the in for writing 
     var sIn = proc.StandardInput; 

     using (var strm = File.OpenText(strFilePath)) 
     { 
      // Write each line of the batch file to standard input 
      while (strm.Peek() != -1) 
      { 
       sIn.WriteLine(strm.ReadLine()); 
      } 
     } 

     // Exit CMD.EXE 

     sIn.WriteLine(String.Format("# {0} run successfully. Exiting", strFilePath)); 
     sIn.WriteLine("EXIT"); 

     // Read the sOut to a string. 
     var results = proc.StandardOutput.ReadToEnd().Trim(); 

     // Write out the results. 
     string fmtStdOut = "<font face=courier size=0>{0}</font>"; 
     this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine, "<br>"))); 
    } 
}