So drucken Sie ein Dokument mithilfe von C# - code?

Will ich drucken Sie ein Dokument mithilfe von C#. Ich habe zwei buttons. btnUpload uploads oder wählt eine word-Datei. btnPrinthave zu senden hochgeladene Datei an einen Drucker. Wie kann ich dies tun? Jetzt mit:

private void btnUpload_Click(object sender, EventArgs e)
{
    string fileName;
    //Show the dialog and get result.
    OpenFileDialog ofd = new OpenFileDialog();
    DialogResult result = openFileDialog1.ShowDialog();
    if (result == DialogResult.OK) //Test result.
    {
        fileName = ofd.FileName;

        var application = new Microsoft.Office.Interop.Word.Application();
        //var document = application.Documents.Open(@"D:\ICT.docx");
        var document = application.Documents.Open(@fileName);
    }
}


private void btnPrint_Click(object sender, EventArgs e)
{
    PrintDialog printDlg = new PrintDialog();
    PrintDocument printDoc = new PrintDocument();
    printDoc.DocumentName = "fileName";
    printDlg.Document = printDoc;
    printDlg.AllowSelection = true;
    printDlg.AllowSomePages = true;
    //Call ShowDialog
    if (printDlg.ShowDialog() == DialogResult.OK)
        printDoc.Print();
}

Schreibe einen Kommentar