c#服务器上的文件怎么打印机,如何通过使用C#窗口服务通过打印机打印数据打印文本文件...

你可以做这样的事情......

注:这是示例代码如何使用C#窗口服务打印PDF文件,如果你要打印的文本文件,你可以更改此代码

带有按钮(cmdGetPrinters)和ListView的Windows窗体 (lstPrinters)。列表视图有两列定义 - “属性”和 “值”,它将描述安装在本地 机器上的打印机。下面的代码实现了魔术。

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data; System.Drawing;

using System.Text; System.Windows.Forms;

using System.Management;

using System.Management.Instrumentation;

public partial class frmPrintDisplay : Form

{

public frmPrintDisplay()

{

InitializeComponent();

}

private void cmdGetPrinters_Click(object sender, EventArgs e)

{

ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Printer");

ManagementObjectSearcher mo = new ManagementObjectSearcher(query);

ManagementObjectCollection printers = mo.Get();

foreach (ManagementObject printer in printers)

{

PropertyDataCollection printerProperties = printer.Properties;

string printerPath = printer.Path.ToString() ;

PropertyDataCollection.PropertyDataEnumerator test =

printer.Properties.GetEnumerator();

while(! (test.MoveNext()== false))

{

lstPrinters.Items.Add(

new ListViewItem(new string[]

{

test.Current.Name,

(

(test.Current.Value == null) ?

"n/a" : test.Current.Value.ToString()

)

})

);

}

}

}

}

此图显示了这个小窗口应用程序的结果。请注意“名称”属性,这将用于将文本文件发送到打印机。这显示在打印机的“ShareName”属性下。在同一个域/工作组中的测试机器上,您必须安装新的网络打印机,并指出安装情况以查看第一台计算机上的共享打印机。这实际上使得第一台计算机成为了打印机服务器,并且您可以为客户端重新设置设置。

现在到测试机......应用上述code building保存文本文件到一个临时目录名为C:\ Program Files文件[应用程序名称] \ TEMP \

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data; System.Drawing;

using System.IO;

using System.Text; System.Windows.Forms;

using System.Management;

using System.Management.Instrumentation;

private void print(ref DirectoryInfo tempDir)

{

try

{

foreach(FileInfo file in tempDir.GetFiles("*.pdf"))

{

file.CopyTo("\\\\XYZ\\Phaser77\\" + file.Name);

}

}

catch(Exception ee){ }

}

我希望这将有助于你

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值