RT
解决方案 »
- 为什么我的VS2008里没有GridView
- --------------复杂的页面跳转问题怎样解决,请进
- 关于正则表达式的问题
- 我习惯把在窗体上要完成的所有功能函数(如数据库访问、显示控件如TreeView、组合框等操作、一般函数等等)都放在窗体类中,随着函数的增多总觉得不太合适,到底应该怎么弄。
- 这句话啥意思
- 回车触发button事件
- 简单问题,送分,关于水晶报表:未定义类型CrystalReport1
- 請問Winfrom中如何在DataGrid加入RadioButton?
- C# 异常处理
- webServices上传的图片的显示问题!!解决马上给分!
- 在C#中,那个控件可以实现将button“归类化”!
- 问大侠:Process类中有没有实现类似API中FindWindow的方法?
using System.Diagnostics;
using System.ComponentModel;namespace MyProcessSample
{
/// <summary>
/// Shell for the sample.
/// </summary>
public class MyProcess
{
// These are the Win32 error code for file not found or access denied.
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5; /// <summary>
/// Prints a file with a .doc extension.
/// </summary>
public void PrintDoc()
{
Process myProcess = new Process();
try
{
// Get the path that stores user documents.
string myDocumentsPath =
Environment.GetFolderPath(Environment.SpecialFolder.Personal); myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
} else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message +
". You do not have permission to print this file.");
}
}
}
public static void Main()
{
MyProcess myProcess = new MyProcess();
myProcess.PrintDoc();
}
}
}