c# - Not able to print a document -


one of methods used :

                printdocument doc = new printdocument();                 doc.printersettings.printername = "printername";                  string[] files = directory.getfiles("d:\\invoice");                 foreach (string file in files)                 {                     string fname = path.getfilename(file);                     doc.documentname = fname;                     doc.print();                     console.writeline(file);                 } 

this gives exception on doc.print() line.

"settings access printer 'printername' not valid."

the other method used :

                process printjob = new process();                 printjob.startinfo.filename = @"c:\program files (x86)\adobe\reader 10.0\reader\acrord32.exe";                 printjob.startinfo.useshellexecute = false;                 printjob.startinfo.verb = "print";                 printjob.startinfo.createnowindow = true;                 printjob.startinfo.windowstyle = processwindowstyle.hidden;                 printjob.startinfo.arguments = "\"" + printeraddress + "\"";                 string[] files = directory.getfiles("d:\\invoice");                 foreach (string file in files)                 {                     string fname = path.getfilename(file);                     printjob.startinfo.workingdirectory = path.getdirectoryname(fname);                      printjob.start();                      //console.writeline(fname);                 } 

this gives error after printjob.start(). pdf file, opens adobe reader , displays error message there. hopw explains.

"there error opening document. file not found."

can me on these issues?

in 2nd snippet, seems wrong:

string fname = path.getfilename(file); printjob.startinfo.workingdirectory = path.getdirectoryname(fname); printjob.start(); 

you set workingdirectory. how printjob actual file name?


in 1st snippet, not setting everything. have checked the msdn documentation? it's idea try find, read , try understand docs, before asking @ so...


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -