-
Printers Collection
Hi,
I am using the following code to get the count of installed printers and
then get the printer name. But it gives me error: Request for the permission
of type System.Drawing.Printing.PrintingPermission, System.Drawing, Version=1.0.2411.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a failed.
Below is the code:-
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Drawing.Printing.PrintPageEventArgs
Imports System.Drawing.Brush
Imports System.Drawing.Printing.PrinterSettings
Imports System.Drawing.Printing.PrinterSettings.StringCollection
Dim pd As PrintDocument
Dim bytInstalledPrinters As Byte
Dim bytCtr As Byte
Try
bytInstalledPrinters = pd.PrinterSettings.InstalledPrinters.Count
For bytCtr = 0 To bytInstalledPrinters
MessageBox.Show(pd.PrinterSettings.InstalledPrinters.Item(bytCtr))
Next
Catch myexception As Exception
MessageBox.Show(myexception.Message)
End Try
Can anyone suggest what's wrong with the above code?
-
Re: Printers Collection
Vilas:
Imports System.Drawing.Printing.PrinterSettings
Module Module1
Sub Main()
Dim printer As String
For Each printer In InstalledPrinters
Console.WriteLine(printer)
Next
Console.WriteLine("{0} printer(s) installed",
InstalledPrinters.Count)
End Sub
End Module
--
Ed Courtenay
http://www.edcourtenay.co.uk
((wrong && wrong) != right)
"Vilas Jain" <vilasj@compulnk.com> wrote:
>
>Hi,
>
>I am using the following code to get the count of installed printers
>and then get the printer name. But it gives me error: Request for the
>permission of type System.Drawing.Printing.PrintingPermission, >System.Drawing,
Version=1.0.2411.0, Culture=neutral,
>PublicKeyToken=b03f5f7f11d50a3a failed.
>
>Below is the code:-
>
>
>Imports System.Drawing
>Imports System.Drawing.Printing
>Imports System.Drawing.Printing.PrintPageEventArgs
>Imports System.Drawing.Brush
>Imports System.Drawing.Printing.PrinterSettings
>Imports System.Drawing.Printing.PrinterSettings.StringCollection
>
>Dim pd As PrintDocument
>Dim bytInstalledPrinters As Byte
>Dim bytCtr As Byte
>
> Try
> bytInstalledPrinters = pd.PrinterSettings.InstalledPrinters.Count
>
> For bytCtr = 0 To bytInstalledPrinters
> MessageBox.Show(pd.PrinterSettings.InstalledPrinters.Item(bytCtr))
> Next
>
> Catch myexception As Exception
> MessageBox.Show(myexception.Message)
>End Try
>
>Can anyone suggest what's wrong with the above code?
>
>
-
Re: Printers Collection
Hi Courtenay,
Thanks for your resonse. I tried the code that you have sent. But the For
statement, it give the same error: (Note: I am using VB.NET Beta 2)
An unhandled exception of type 'System.Security.SecurityException' occurred
in mscorlib.dll
Additional information: Request for the permission of type System.Drawing.Printing.PrintingPermission,
System.Drawing, Version=1.0.2411.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
failed.
Is there anything wrong with my environment?
Regards,
Vilas
"Ed Courtenay" <ed@edcourtenay.co.uk> wrote:
>
>Vilas:
>
>Imports System.Drawing.Printing.PrinterSettings
>
>Module Module1
>
> Sub Main()
> Dim printer As String
> For Each printer In InstalledPrinters
> Console.WriteLine(printer)
> Next
> Console.WriteLine("{0} printer(s) installed",
>InstalledPrinters.Count)
> End Sub
>
>End Module
>
>--
>Ed Courtenay
>http://www.edcourtenay.co.uk
>((wrong && wrong) != right)
>
>"Vilas Jain" <vilasj@compulnk.com> wrote:
>>
>>Hi,
>>
>>I am using the following code to get the count of installed printers
>>and then get the printer name. But it gives me error: Request for the
>>permission of type System.Drawing.Printing.PrintingPermission, >System.Drawing,
>Version=1.0.2411.0, Culture=neutral,
>>PublicKeyToken=b03f5f7f11d50a3a failed.
>>
>>Below is the code:-
>>
>>
>>Imports System.Drawing
>>Imports System.Drawing.Printing
>>Imports System.Drawing.Printing.PrintPageEventArgs
>>Imports System.Drawing.Brush
>>Imports System.Drawing.Printing.PrinterSettings
>>Imports System.Drawing.Printing.PrinterSettings.StringCollection
>>
>>Dim pd As PrintDocument
>>Dim bytInstalledPrinters As Byte
>>Dim bytCtr As Byte
>>
>> Try
>> bytInstalledPrinters = pd.PrinterSettings.InstalledPrinters.Count
>>
>> For bytCtr = 0 To bytInstalledPrinters
>> MessageBox.Show(pd.PrinterSettings.InstalledPrinters.Item(bytCtr))
>> Next
>>
>> Catch myexception As Exception
>> MessageBox.Show(myexception.Message)
>>End Try
>>
>>Can anyone suggest what's wrong with the above code?
>>
>>
>
-
Re: Printers Collection
I've no idea - maybe there's a network printer you don't have access to
somewhere?
--
Ed Courtenay
http://www.edcourtenay.co.uk
((wrong && wrong) != right)
"Vilas Jain" <vilasj@compulnk.com> wrote in message
news:3bb414ef$1@news.devx.com...
>
> Hi Courtenay,
>
> Thanks for your resonse. I tried the code that you have sent. But the For
> statement, it give the same error: (Note: I am using VB.NET Beta 2)
>
> An unhandled exception of type 'System.Security.SecurityException'
occurred
> in mscorlib.dll
>
> Additional information: Request for the permission of type
System.Drawing.Printing.PrintingPermission,
> System.Drawing, Version=1.0.2411.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
> failed.
>
> Is there anything wrong with my environment?
>
> Regards,
>
> Vilas
>
>
>
>
> "Ed Courtenay" <ed@edcourtenay.co.uk> wrote:
> >
> >Vilas:
> >
> >Imports System.Drawing.Printing.PrinterSettings
> >
> >Module Module1
> >
> > Sub Main()
> > Dim printer As String
> > For Each printer In InstalledPrinters
> > Console.WriteLine(printer)
> > Next
> > Console.WriteLine("{0} printer(s) installed",
> >InstalledPrinters.Count)
> > End Sub
> >
> >End Module
> >
> >--
> >Ed Courtenay
> >http://www.edcourtenay.co.uk
> >((wrong && wrong) != right)
> >
> >"Vilas Jain" <vilasj@compulnk.com> wrote:
> >>
> >>Hi,
> >>
> >>I am using the following code to get the count of installed printers
> >>and then get the printer name. But it gives me error: Request for the
> >>permission of type System.Drawing.Printing.PrintingPermission,
>System.Drawing,
> >Version=1.0.2411.0, Culture=neutral,
> >>PublicKeyToken=b03f5f7f11d50a3a failed.
> >>
> >>Below is the code:-
> >>
> >>
> >>Imports System.Drawing
> >>Imports System.Drawing.Printing
> >>Imports System.Drawing.Printing.PrintPageEventArgs
> >>Imports System.Drawing.Brush
> >>Imports System.Drawing.Printing.PrinterSettings
> >>Imports System.Drawing.Printing.PrinterSettings.StringCollection
> >>
> >>Dim pd As PrintDocument
> >>Dim bytInstalledPrinters As Byte
> >>Dim bytCtr As Byte
> >>
> >> Try
> >> bytInstalledPrinters = pd.PrinterSettings.InstalledPrinters.Count
> >>
> >> For bytCtr = 0 To bytInstalledPrinters
> >>
MessageBox.Show(pd.PrinterSettings.InstalledPrinters.Item(bytCtr))
> >> Next
> >>
> >> Catch myexception As Exception
> >> MessageBox.Show(myexception.Message)
> >>End Try
> >>
> >>Can anyone suggest what's wrong with the above code?
> >>
> >>
> >
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks