C# .NET - how to print without print dialog

Asked By MJ L
04-Jan-10 03:17 AM

I need source code reference of that.

after just click button event, now showing print dialog, print start

it's what I wanted.

thanks your reply in advance.

re  re

04-Jan-10 03:27 AM

It depends on from where you wanted to print, you can check this on how to print from browser control with and without print dialog

http://www.ussbd.com/printhtm.html

And, you could print without print dialog using print method on printdocument..

 

how to print without print dialog  how to print without print dialog

04-Jan-10 03:35 AM

The following links does this,

http://www.ussbd.com/printhtm.html

http://www.velocityreviews.com/forums/t118409-printing-from-web-form-without-print-dialog.html


Thanks and Regards,
http://www.CodeCollege.NET
http://www.InterviewsGuru.info

 

Re  Re

04-Jan-10 03:49 AM
You can use the DOS print command for successfull silent printing. The syntax is 

PRINT [/D:(printer name)] [filename with path]

In order to use this command in C# create a batch file in the file system with content as shown below

PRINT /D:%1 %2

%1 and %2 will act as place holders for your command line arguments. In the .net code use Process class as shown below

public void PerformSilentPrinting(string fileName, string printerName)
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
             startInfo.Arguments = string.Format("{0} {1}", printerName, fileName);
             //Will execute the batch file with the provided arguments
           Process process = Process.Start(startInfo);
             //Reads the output
             string output = process.StandardOutput.ReadToEnd();
}
catch
{
//Do exception handling
}
}
print without print dialog  print without print dialog
04-Jan-10 07:01 AM

You can create a PrintDocument, then call the Print method. It does not show a Print Dialog, since you can manually set the options.

Go thr these links as well;

http://www.ussbd.com/printhtm.html

http://ondotnet.com/pub/a/dotnet/2002/06/24/printing.html

http://www.velocityreviews.com/forums/t118409-printing-from-web-form-without-print-dialog.html

Create New Account
help
Close(); } HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); using (StreamReader reader = new StreamReader(webResponse.GetResponseStream())) { _rawResult = reader.ReadToEnd(); reader.Close(); } webResponse.Close(); } catch (Exception e) { _message = e.Message; } Jonathan C# Discussions HttpWebResponse.IDisposable.Dispose (1) FileNotFoundException (1) DbConnection.ExecuteReader new StreamReader(webResponse.GetResponseStream())) { / / code here } It need not be messy. No. Yes. If the class implements IDisposable, then you need the "using" statement. If it doesn't, you don't using statements instead. Hopefully not a big deal. Exactly. Look at the documentation. Every .NET class has on the first doc page for that class a complete description of all classes it inherits and interfaces it implements. If the class implements IDisposable, it will say so there. Alternatively, you could always just look for the Dispose() or IDisposable.Dispose() interface in the class methods. Generally speaking it should. However, I can't rule out the possibility of a class that requires explicit closing for best results. A Close() method may have other semantics than
Exception handling could any one send me the best practices of exception handling in cs code and also in stored procedures for 4 + years .net developer range for a real time examples, this link may help you: http: / / www.codeproject.com / KB / exception / RealTimeDebugger.aspx Thanks A well-designed set of error handling code blocks can make a example, you can programmatically check for a condition that is likely to occur without using exception handling. In other situations, using exception handling to catch an error condition is appropriate. The following example uses an if statement check whether a connection is closed. You can use this method instead of throwing an exception if the connection is not closed. A few basic design concepts will make your program most common "bad code" that you can introduce in your projects, when it comes to exception handling. Don't throw new Exception() Please, don't do it. Exception is a too broad class, and it's hard
crashing at this line below and throwing this kind of error (The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))) newChartObject = chartObjects.Add(0, 100, 300, 300); The first thing I is all my code for this function, I wanted to throw this code in a class of its own, a class design to handle the creation of the excel chart but out of desperation decided to move it back to my class where I handle the creation of the excel doc, thinking that would work but it swith back workSheet_range = getWorkSheet(1).get_Range("B4", "B100"); newChartObject = chartObjects.Add(0, 100, 300, 300); <- -- -- -- - Exception thrown here newChartObject.Chart.ChartWizard(workSheet_range, Excel.XlChartType.xlLine, 1, Excel.XlRowCol.xlColumns, misValue, misValue, misValue, misValue, misValue, misValue, misValue); } - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Here is my code for my class Create Excel doc using System; using System.Windows.Forms; using System.Collections.Generic; using System Linq; using System.Text; using System.Reflection; using Excel = Microsoft.Office.Interop.Excel; namespace securities_Research { class CreateExcelDoc { private Excel._Application app = null; / / Creates the excel doc private Excel._Workbook workbook = null
is the code for the same. on reaching 45 to 48 kb it is throwing exception as "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll".Instead of writing to notepad i tried Application.StartupPath & " \ LOGFILE \ " & sLogFile) End If Dim sw As New System.IO.StreamWriter(fs) ' the exception is throwed at this point 'sw.WriteLine(Now & ":" & Now.Millisecond & vbCrLf & LogData & vbCrLf) 'sw.WriteLine(Now & vbCrLf & LogData & vbCrLf) 'sw.WriteLine(" ") 'sw.Close() 'fs.Close() Catch ex As Exception LogError(ex.ToString()) End Try End Sub Why do you open a file stream and file Option Explicit On Option Strict On Imports System Imports System.IO Imports Microsoft.VisualBasic Class DirAppend Public Shared Sub Main() Dim w As StreamWriter = File.AppendText(sLogFile) Log( "Test1" , w the file. Dim r As StreamReader = File.OpenText( "log.txt" ) DumpLog(r) End Sub End Class Here we are using File.AppendText method. This does two things 1. If the file Using writer As StreamWriter = New StreamWriter(filePath) write.WriteLine(DataBytes); End Using Catch ex As Exception LogError(ex.ToString()) End Try End Sub Now it is throwing the exception on reaching 90 kb / / Reading private void button1_Click( object sender, EventArgs e) { System.IO. StreamReader
How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote Cache substitution? Chapter 6: OOPS (B) What is Object Oriented Programming? (B) What is a Class? (B) What is an Object? (A) What is the relation between Classes and Objects? (B Overriding? (I) what is the difference between delegate and events? (B) If we inherit a class do the private variables also get inherited? (B) What is the different accessibility levels defined in .NET? (I) Can you prevent a class from overriding? (I) what is the use of “Must inherit” keyword in VB.NET? (I Do interface have accessibility modifier. (A) What are similarities between Class and structure? (A) What is the difference between Class and structure’s? (B) What does virtual keyword mean? (B) What are shared (VB.NET 9: ADO.NET (B) What is the namespace in which .NET has the data functionality class? (B) Can you give an overview of ADO.NET architecture? (B) What are the two