Connecting Tech Pros Worldwide Help | Site Map

Printing an image from file on a network

Hutt's Avatar
Newbie
 
Join Date: Jan 2008
Posts: 5
#1: Feb 18 '08
Hi,

asp.net (vb).
I have developed a site in test on my PC which runs a process and outputs a jpeg image to a folder in C:\inetpub\wwwroot\images, and I can print it from a button on my page using vb with document.print().
However, when I move the site to our server the print no longer works. I understand this is because the image is now on the server along with the vb code.
So my question is how can a client on a network get the image file from the server and print it with the simple click of a button on the web page? I have tried looking into Javascript to do this, but all I can find are examples that print the current page, not an image file from a server.
Thank you.
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Feb 18 '08

re: Printing an image from file on a network


This is probably easier than you think. Use an IP or domain to access page and print image (IIS). On a large network you will have a server that hosts your (intranet) application. HTH.
Hutt's Avatar
Newbie
 
Join Date: Jan 2008
Posts: 5
#3: Feb 18 '08

re: Printing an image from file on a network


Hi,
Thanks for replying, but I'm relatively new to .net and need some clearer advice. Yes my application is on a network web server, and this is where the jpeg image file sits. The client could open the image in a browser to print, but that doesn't work because it only ever prints part of the image (despite changing printer settings to fit to page), and this involves another step for the user. When I host the app locally my .net code fits the image to the A4 page and prints , so I am looking for some code that will work when it is hosted on the web server and the client wants to print the image.
Below is the code that runs on my PC but not when on the server, apparently I have to use the path to the image, a URL is no good:

Sub DocumentPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim theCompleteImage As New Drawing.Bitmap("C:\Inetpub\wwwroot\Prints\" + _imgStr + ".jpg")
Try
'Actual image is larger, this will fit to print page A4P
e.Graphics.DrawImage(theCompleteImage, 0, 0, 740, 1110)
Finally
theCompleteImage.Dispose()
End Try
End Sub

Public Sub PrintMethod(ByVal strInput As String)
_imgStr = strInput 'the image name
Dim document As New Drawing.Printing.PrintDocument()
AddHandler document.PrintPage, AddressOf DocumentPrintPage
document.Print()
End Sub
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#4: Feb 19 '08

re: Printing an image from file on a network


Hint - IP or domain replaces your local drive. HTH.
Hutt's Avatar
Newbie
 
Join Date: Jan 2008
Posts: 5
#5: Feb 19 '08

re: Printing an image from file on a network


Quote:

Originally Posted by kenobewan

Hint - IP or domain replaces your local drive. HTH.

Hi,
If I change the line to:
Dim theCompleteImage As New Drawing.Bitmap("http://localhost/Prints/" + _imgStr + ".jpg")
and run the app it highlights this line of code, with a message 'URI formats are not supported'. What am I missing?
Thanks.
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#6: Feb 20 '08

re: Printing an image from file on a network


Must admit that was a surprize, apparently you use Server.MapPath().
Newbie
 
Join Date: Feb 2008
Posts: 1
#7: Feb 27 '08

re: Printing an image from file on a network


I've got the same problem. This link will help you:
http://www.csharphelp.com/board2/rea...&i=9298&t=9289
Good luck!
Reply