473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Re: Printing problem using - System.Diagnostics.ProcessStartInfo s

Hi Mike

I have changed the code using Server.MapPath but to no avail.
Prints the Adobe PDF document to the default local printer
(I am running this localhost). I Have not run it on the server yet.

What confuses me is

1. All the documents to be printed are in the same directory -
The application directory - so the authorities to the objects
should all be the same. All objects have the same Access
properties.If it can find the PDF document then why can't
it find the .doc and .xls documents.
2. Each of the applications starts up. Adobe, Excel, Word.
I can see the application start in the task manager.
This suggests that both Excel and Word are trying to
perform the required action but failing;
3. The catch throws an Access Denied exception in response
to the error.
(The catch does not throw an exception if there is an existing
instance of the Word or Excel application running. The page
just hangs and no exception is thrown).
I have a small piece of code to forceably kill the process if
it does not end itself. In both the Excel and WORK instances
the code throws an exception

No process is associated with this object

try
{
if (myProcess.HasExited == false)
{
myProcess.Kill();
}
}
catch (Win32Exception ex)
{
label1.Text = label1.Text + "<br><br><br>" + "Cannot Kill Process :
Error Code = " +
ex.ErrorCode + "<br>" + "Base Exception Is " +
ex.GetBaseException() + "<br>" + "Inner Exception Is " +
ex.InnerException + "<br><br><br>";
}
Surely if the process has started then there must be a process
associated with the process object !!!!

I am confused.

best regards

Iain
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++

Code
-------

try
{
myProcess.StartInfo.FileName = Server.MapPath (PFileName);
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit(20000);
}
catch (Win32Exception ex)
{
if(ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
label1.Text = label1.Text + "<br><br><br>" + "Path Error : " +
ex.Message + "<br><br><br>";
}
else
if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
{
label1.Text = label1.Text + "<br><br><br>" + "Permission Error : "
+ ex.Message + "<br><br><br>";
}
else
{
label1.Text = label1.Text + "<br><br><br>" + "Unknown Error : " +
ex.Message + "<br><br><br>";
}
}
Jun 27 '08 #1
2 4809
Outside of the web application with the word and xls files where the website
tries to open them, can you successfully open them from windows explorer?
Also try printing from explorer. I'm hoping this will provide a clue to what
is going on with office files.

"Iain Wilson" wrote:
Hi Mike

I have changed the code using Server.MapPath but to no avail.
Prints the Adobe PDF document to the default local printer
(I am running this localhost). I Have not run it on the server yet.

What confuses me is

1. All the documents to be printed are in the same directory -
The application directory - so the authorities to the objects
should all be the same. All objects have the same Access
properties.If it can find the PDF document then why can't
it find the .doc and .xls documents.
2. Each of the applications starts up. Adobe, Excel, Word.
I can see the application start in the task manager.
This suggests that both Excel and Word are trying to
perform the required action but failing;
3. The catch throws an Access Denied exception in response
to the error.
(The catch does not throw an exception if there is an existing
instance of the Word or Excel application running. The page
just hangs and no exception is thrown).
I have a small piece of code to forceably kill the process if
it does not end itself. In both the Excel and WORK instances
the code throws an exception

No process is associated with this object

try
{
if (myProcess.HasExited == false)
{
myProcess.Kill();
}
}
catch (Win32Exception ex)
{
label1.Text = label1.Text + "<br><br><br>" + "Cannot Kill Process :
Error Code = " +
ex.ErrorCode + "<br>" + "Base Exception Is " +
ex.GetBaseException() + "<br>" + "Inner Exception Is " +
ex.InnerException + "<br><br><br>";
}
Surely if the process has started then there must be a process
associated with the process object !!!!

I am confused.

best regards

Iain
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++

Code
-------

try
{
myProcess.StartInfo.FileName = Server.MapPath (PFileName);
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit(20000);
}
catch (Win32Exception ex)
{
if(ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
label1.Text = label1.Text + "<br><br><br>" + "Path Error : " +
ex.Message + "<br><br><br>";
}
else
if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
{
label1.Text = label1.Text + "<br><br><br>" + "Permission Error : "
+ ex.Message + "<br><br><br>";
}
else
{
label1.Text = label1.Text + "<br><br><br>" + "Unknown Error : " +
ex.Message + "<br><br><br>";
}
}
Jun 27 '08 #2
From Windows explorer I can

Open both the Excel and Word documents (All looks well) and Right
click and print both documents.

When I right click and select print

The appropriate application opens up
The document is sent to the printer
The application closes down
The document is printed.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Barry Munro | last post by:
Hi, I'm using the following code to print documents from the file system but i'm encountering strange behaviour. If I print one document it works ok but if i say loop round a list of files and...
0
by: Daniel Reber | last post by:
I am trying to start a process from a windows service but when the process starts the command window that the process runs in never shows. Is this because I am calling it from a windows service? ...
1
by: Morten | last post by:
Hi! Does anyone know why the code below always returns an "access is denied" error? private void Page_Load(object sender, System.EventArgs e) { System.Diagnostics.Process meProc =...
2
by: Eranga | last post by:
I have a windows application in C# which has the following method public void InitiateSession(string server,string userName, string passWd ) { //To start the command...
5
by: David Conorozzo | last post by:
I am able to create new sources using CreateEventSource. I can call GetEventLogs, I can delete sources, I can see if sources exist BUT, as soon as I try a "WriteEntry", I get an exception: ...
1
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window....
1
by: Jiho Han | last post by:
I am wondering whether asp.net applications can write trace information using the System.Diagnostics.Trace class, and also whether in web.config, the <system.diagnostics> element and its sub...
0
by: Speech Lover | last post by:
I am trying to find a sample from the Internet about invoking a command line from .NET 2.0 by using System.Diagnostics.Process with Domain, UserName and Password specified? All samples I found so...
1
by: anup2331 | last post by:
Hi there, I want to execute the "C:\Program Files\ABCD\Metro1.1\Converter\mysoftware.exe D:\\Test\SOMEFILE.ADT C:\Program Files\ABCD\Metro1.1\CSV\somefile.csv 0" But it gives me an error....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.