Печать на основе DOS через ASP.NET - PullRequest
2 голосов
/ 25 апреля 2009

Ну, моя ситуация такова:

Я создаю отчет в виде текстового файла на сервере, который необходимо распечатать в режиме DOS на матричном принтере. Я хочу избежать печати Windows, потому что это будет слишком медленно. Есть ли способ в ASP.NET, с помощью которого я могу выполнять печать на основе DOS, так как она лучше всего подходит для матричных принтеров Dot. Я обыскивал сеть, но не мог найти ни одного решения или указателей. Есть ли в каком-либо органе какие-либо указатели / решения, которые они могли бы внедрить или наткнуться на них.

Это приложение представляет собой веб-приложение.

Thanx.

Ответы [ 2 ]

4 голосов
/ 25 апреля 2009

Если я вас правильно понял, один из вариантов - запустить пакетный файл, который будет выполнять фактическую печать из ASP.NET. Начиная с здесь : (очевидно, вы можете пропустить часть кода, записывающего вывод на страницу)

// 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 голосов
/ 25 апреля 2009

Ответ от BobbyShaftoe правильный. Вот педантичная версия этого:

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>")));
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...