Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one or more files in a folder. When i click on Print button in asp.net, I should print all the files from this folder without opening them.

How can I do this in ASP.NET.
Posted
Comments
E.F. Nijboer 5-Aug-10 3:44am    
The code behind is going to print it on the server? You have to open them in order to print them of course but you do not want to stall the server with this task, correct? Could a print service you create yourself be a solution. You put folders in a queue for the print server and let this service handle it. Otherwise, do you have more info on what you exactly want? or want to avoid (since you don't want to open the files)
Shining Legend 5-Aug-10 5:49am    
Actually i want to print without opening the files in asp.net on button click.

I am using below code for printing :

protected void btnPrint_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/Documents/");

//Get all the files from the Directory
string[] docFiles = Directory.GetFiles(path);

//Loop through the files
for (int count = 0; count < docFiles.Length; count++)
{
PrintFiles(docFiles[count]);
}
}

void PrintFiles(string fileToPrint)
{
Process pro = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = false;
info.FileName = string.Format("PRINT \\\\10.138.77.54\\HP LaserJet 5000 Series PCL6", fileToPrint);
pro.StartInfo = info;//Exception is throw here
pro.Start();
}

Win32Exception was unhandled by user code. The system cannot find the file specified.

The file it is trying to print is there. Here the printer is on server which is not the local machine. Please tell me in the following line how can i get the reference to the printer and give the print command.


info.FileName = string.Format("PRINT \\\\10.138.77.54\\HP LaserJet 5000 Series PCL6", fileToPrint);
 
Share this answer
 
Please don't push 'answer' to post more questions. Edit your post. As you say, your code can only ever print documents that are on the server, using a printer that is on the server. Given that this is utterly worthless for any sort of web app, and would need to be run inside a local network to make any sense at all, I suggest you don't want to use your web app to do this, you could have your web app trigger a service that does it, or just write some code to do it.

I do think you need to check the string you're generating, learn to use @ to build strings that are readable, and I also don't think that string.Format is doing what you expect here. You're not adding fileToPrint at all, let along adding it in quotes. I think your core issue may well be just that you haven't bothered to debug your code, and your FileName is totally wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900