Jignesh Patel
Jignesh Patel

Reputation: 316

Print prn file using bat file

    private void button1_Click(object sender, EventArgs e)
    {
                    ttime = DateTime.Now.ToString("dd-MM-yyyy");

        string folderName = @"c:\PRN File";
        @System.IO.Directory.CreateDirectory(folderName);

        String path = @"c:\PRN File\myFile.prn"; 
        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
        { 
            using (TextWriter tw = new StreamWriter(fs))
        {
            tw.WriteLine("<xpml><page quantity='0' pitch='76.2 mm'></xpml>SIZE 76.2 mm, 76.2 mm");
            tw.WriteLine("DIRECTION 0,0");
            tw.WriteLine("REFERENCE 0,0");
            tw.WriteLine("OFFSET 0 mm");
            tw.WriteLine("SET PEEL OFF");
            tw.WriteLine("SET CUTTER OFF");
            tw.WriteLine("<xpml></page></xpml><xpml><page quantity='1' pitch='76.2 mm'></xpml>SET TEAR ON");
            tw.WriteLine("CLS");
            tw.WriteLine("CODEPAGE 1252");
            tw.WriteLine("TEXT 579,370,\"ROMAN.TTF\";,180,1,12,\"Party Name:\"");
            tw.WriteLine("BARCODE 527,546,\"128M\",102,0,180,3,6,\"!104CR!0991234567890123445\"");
            tw.WriteLine("TEXT 451,439,\"ROMAN.TTF\",180,1,12,\"CR1234567890123445\"");
            tw.WriteLine("TEXT 579,329,\"ROMAN.TTF\",180,1,12,\"Order no:\"");
            tw.WriteLine("TEXT 579,289,\"ROMAN.TTF\",180,1,12,\"Ref No:\"");
            tw.WriteLine("TEXT 579,249,\"0\",180,13,10,\"Date:\"");
            tw.WriteLine("TEXT 579,209,\"ROMAN.TTF\",180,1,12,\"W X H:\"");
            tw.WriteLine("TEXT 579,169,\"ROMAN.TTF\",180,1,12,\"Prd Ty:\"");
            tw.WriteLine("TEXT 579,128,\"ROMAN.TTF\",180,1,12,\"Remarks:\"");
            tw.WriteLine("TEXT 392,370,\"ROMAN.TTF\",180,1,12,\"AMI Distributors\"");
            tw.WriteLine("TEXT 439,329,\"ROMAN.TTF\",180,1,12,\"" + order_no + "\"");
            tw.WriteLine("TEXT 460,289,\"ROMAN.TTF\",180,1,12,\"" + o_ref + "\"");
            tw.WriteLine("TEXT 497,249,\"0\",180,13,10,\"" + ttime + "\"");
            tw.WriteLine("TEXT 477,209,\"ROMAN.TTF\",180,1,12,\"" + w + "" + u + " X " + h + "" + u + "\"");
            tw.WriteLine("TEXT 472,169,\"ROMAN.TTF\",180,1,12,\"" + pro + "\"");
            tw.WriteLine("TEXT 436,128,\"ROMAN.TTF\",180,1,12,\"" + oprating + "\"");
            tw.WriteLine("PRINT 1,1");
            tw.WriteLine("<xpml></page></xpml><xpml><end/></xpml>");

            }
        }


        Process proc = null;
        try
        {
            string batDir = string.Format(@"c:\PRN File\");
            proc = new Process();
            proc.StartInfo.WorkingDirectory = batDir;
            proc.StartInfo.FileName = "a.bat";
            proc.StartInfo.CreateNoWindow = false;
            proc.Start();
            proc.WaitForExit();
            MessageBox.Show("File Print Success");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.StackTrace.ToString());
        }

}

in a.bat file : copy myFile.prn LPT1

myFile.prn i won't print this file,myFile.prn also in same directory

when i run bat file print proper, but using window from on print button click nothing happen.

i don't know what's problem i this c drive not allow me to run file or other

Upvotes: 0

Views: 1376

Answers (2)

Jignesh Patel
Jignesh Patel

Reputation: 316

C drive permission issue. I change my storage location and its working proper

Upvotes: 0

TLJ
TLJ

Reputation: 4945

You can try to add app.manifest just to see if it is about permission issue.

Application Manifest File setting in Visual Studio

In your app.manifest

change :<requestedExecutionLevel level="asInvoker" uiAccess="false" />   
to     :<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />`

Upvotes: 1

Related Questions