First write a standerd c# code in visual studion as shown below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.IO;
namespace PrintFile
{
public class PrintDoc
{
public PrintDoc()
{
}
public void PrintingFile(string FilePath)
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
if (DialogResult.OK == pd.ShowDialog())
{
var printJob = new System.Diagnostics.Process();
printJob.StartInfo.FileName = FilePath;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "print";
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = pd.PrinterSettings.PrinterName;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(FilePath);
printJob.StartInfo.CreateNoWindow = false;
printJob.Start();
printJob.WaitForExit(20000);
if (printJob.HasExited == false)
{
printJob.Kill();
}
}
}
}
}
Now add the reference of System.Drawing and System.Diagnostics.
then go to properties of the project and select sigining Tab-->check sign the assembly and give the strong name.
finally build the code. now we will get the Printfile DLL in the output path of the build Tab.
Copy the dll and paste it in the path C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client\Add-ins.
Now go to navision decalre the variable with dotnet data type and set thte property runonclient--> yes
then write the below code in you object where you want.
here Printfile is the dotnet type varriable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.IO;
namespace PrintFile
{
public class PrintDoc
{
public PrintDoc()
{
}
public void PrintingFile(string FilePath)
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
if (DialogResult.OK == pd.ShowDialog())
{
var printJob = new System.Diagnostics.Process();
printJob.StartInfo.FileName = FilePath;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "print";
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = pd.PrinterSettings.PrinterName;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(FilePath);
printJob.StartInfo.CreateNoWindow = false;
printJob.Start();
printJob.WaitForExit(20000);
if (printJob.HasExited == false)
{
printJob.Kill();
}
}
}
}
}
Now add the reference of System.Drawing and System.Diagnostics.
then go to properties of the project and select sigining Tab-->check sign the assembly and give the strong name.
finally build the code. now we will get the Printfile DLL in the output path of the build Tab.
Copy the dll and paste it in the path C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client\Add-ins.
Now go to navision decalre the variable with dotnet data type and set thte property runonclient--> yes
then write the below code in you object where you want.
here Printfile is the dotnet type varriable.