Network printing
-
Hi everyone I have searched the whole day long now and cant seen to find, maybe searching in the wrong places:confused: If someone could please help me I have a aspx vb project using crystal reports, now what I want to do is , when the user hits the print button the report should print to a printer shared on a computer connected to the network. Now this is working when I run the app in visual studio but when its published to the iis it gives me a "access denied" error when i set the printer as \\pcIP\printername , or when i view the printer queue it says, "error - printing" when i set the printer as a normal printer on the server giving it a new port looking at the same place as before this is how i do it create a report doc -> rpt rpt.PrintOptions.PrinterName = "\\IP\printer" rpt.PrintToPrinter(1, False, 0, 0) any help would be great
-
Hi everyone I have searched the whole day long now and cant seen to find, maybe searching in the wrong places:confused: If someone could please help me I have a aspx vb project using crystal reports, now what I want to do is , when the user hits the print button the report should print to a printer shared on a computer connected to the network. Now this is working when I run the app in visual studio but when its published to the iis it gives me a "access denied" error when i set the printer as \\pcIP\printername , or when i view the printer queue it says, "error - printing" when i set the printer as a normal printer on the server giving it a new port looking at the same place as before this is how i do it create a report doc -> rpt rpt.PrintOptions.PrinterName = "\\IP\printer" rpt.PrintToPrinter(1, False, 0, 0) any help would be great
Ok so no reply from anyone, so I'll leave what I got When using network resources the asp.net "user" doesn’t have the required rights. So , what you need to do is impersonate a user on the sever having the rights the access the network . Create a class, call it whatever you want, I’ll call this one impersonation and add the following: Some of the imports won’t be needed
Imports Microsoft.VisualBasic
Imports System.Web.Security
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Configuration
Imports SR = System.Reflection
Imports System.Text
Imports System.Web.UI.WebControlsPublic Class Impersonation
Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0
Private Const LOGON32_LOGON_INTERACTIVE As Integer = 2
Private Const LOGON32_LOGON_NETWORK As Integer = 3
Private Const LOGON32_LOGON_BATCH As Integer = 4
Private Const LOGON32_LOGON_SERVICE As Integer = 5
Private Const LOGON32_LOGON_UNLOCK As Integer = 7
Private Const LOGON32_LOGON_NETWORK_CLEARTEXT As Integer = 8
Private Const LOGON32_LOGON_NEW_CREDENTIALS As Integer = 9Private Shared ImpersonationContext As WindowsImpersonationContext Declare Function LogonUserA Lib "advapi32.dll" ( \_ ByVal lpszUsername As String, \_ ByVal lpszDomain As String, \_ ByVal lpszPassword As String, \_ ByVal dwLogonType As Integer, \_ ByVal dwLogonProvider As Integer, \_ ByRef phToken As IntPtr) As Integer Declare Auto Function DuplicateToken Lib "advapi32.dll" ( \_ ByVal ExistingTokenHandle As IntPtr, \_ ByVal ImpersonationLevel As Integer, \_ ByRef DuplicateTokenHandle As IntPtr) As Integer Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long Public Shared Function ImpersonateValidUser(ByVal strUserName As String, \_ ByVal strDomain As String, ByVal strPassword As String) As Boolean Dim token As IntPtr = IntPtr.Zero Dim tokenDuplicate As IntPtr = IntPtr.Zero Dim tempWindowsIdentity As WindowsIdentity ImpersonateValidUser = False If RevertToSelf() <> 0 Then If LogonUserA(st