Archive

Archive for January, 2014

Print file without open it in c#

January 22, 2014 Leave a comment

In this method you can put condition of file printing as per file type with attached executable

public static Boolean PrintFile(string fileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = “print”;

//Define location of adobe reader/command line
//switches to launch adobe in “print” mode
proc.StartInfo.FileName = “Your application executable path”;
proc.StartInfo.Arguments = String.Format(@”/p /h {0}”, fileName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}

proc.EnableRaisingEvents = true;

proc.Close();
return true;
}
catch
{
return false;
}

Categories: C#