Printer names in PrinterSettings.InstalledPrinters vs Microsoft.Office.Interop.Word.ApplicationActiv

D

David

Hi All

I have a rather anoying problem. When I look for a printer using C#/.NET and PrinterSettings.InstalledPrinters I get
set of string like "\\mycomputer\sharename". When I look at the current default printer with Microsoft.Office.Interop.Word.ApplicationActivePrinter I get back a string like "\\mycomputer\sharename on port". Whe
I try to assign Microsoft.Office.Interop.Word.ApplicationActivePrinter to something like \\mycomputer\sharename it hangs MS-Word (and thus my program)

Does anyone know how to find a list of printer with their port name? I am using C#, .NET 1.0, and office XP.
 
W

Wei-Dong XU [MSFT]

Hi Dave,

I use the code below to set the ActivePrinter property of word application object.
//------------------------------------------------------------
using Word = Microsoft.Office.Interop.Word;
//...
Word.ApplicationClass app = new Word.ApplicationClass();
app.Visible = true;
object missing = Type.Missing;
app.Documents.Add( ref missing,
ref missing,
ref missing,
ref missing );
app.ActivePrinter = "\\\\<server name>\\2068hp8150";
MessageBox.Show( app.ActivePrinter );
//...
//------------------------------------------------------------

It runs very well. Is this the same to your code? If the same, I'd also suggest you can check whether you have installed Office XP Primary Interop
Assemblies (PIA). Type "%windir%\assembly" (without quotation mark) in start -> run; please check whether there is the Office assemblies, such
as microsoft.Office.Interop.Word etc existing there. If not, please install the Office XP PIAs from the link:
http://www.microsoft.com/downloads/...1E-3060-4F71-A6B4-01FEBA508E52&displaylang=en

This article will introduce more info for you regarding the Office XP PIA,
A Primer to the Office XP Primary Interop Assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office10032002.asp

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Moffatt

Hi Wei-Dong

You responded to a posting I had placed earlier about printer settings and hanging. I have clarified the issue and I think I found a bug. Can I report this via you? If not where should I send this

Here is the issue. If you remove the [STAThread] line from a program then set Microsoft.Office.Interop.Word.ApplicationClass.ActivePrinter it will hang word and your program. I was removing [STAThread] because I have a multithreaded program. Here is a small example that shows the problem. Just hit the “GO†button. All the go button does i

PrinterSettings ps = new PrinterSettings()
printDialog1.PrinterSettings = ps
printDialog1.ShowDialog();
Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass()
/
// If you leave the [STAThread] commented and uncommen
// the line below it will hang
app.ActivePrinter = ps.PrinterName; // <== it hangs her
object missing = System.Reflection.Missing.Value;
app.Quit(ref missing, ref missing, ref missing)
MessageBox.Show("Done")

I am also going to cross post this back to the news group. The source code is attached as a zip file. This was developed on the .NET 1.0 framework.
I verified that I am using the latest version of the PIA as per you earlier post

--Thank you for your time

David Moffatt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top