You cannot directly do this using .NET. However, there are some wrapper classes available at http://www.mentalis.org/soft/class.qpx?id=1 that allow you to do just this. You can download the latest version of these classes directly from the site.
We have packaged these classes as a library and added a simple Winforms sample and made these available here.
This library basically uses the Media Control Interface (MCI).
This can be done using the Process class and specifying the verb as ‘Print’. This is the equivalent of right clicking and selecting print in the windows shell. Here is the code snippet that prints documents like MS Excel, MS Word, pdf etc..
// In C#.NET//Print an Excel document
Process pr = new Process();
pr.StartInfo.Verb = 'Print';
pr.StartInfo.FileName = 'Sample.xls';
pr.Start();
’ In VB.NET
’Print an Excel document
Dim pr As Process = New Process()
pr.StartInfo.Verb = 'Print'
pr.StartInfo.FileName = 'Sample.xls'
pr.Start()
Visual Basic has a GetType operator that can be used to obtain the System.Type object for the specified type name. This is the equivalent of the typeof keyword in C#.
’ Returns the System.RuntimeType object representing the integer type.
Dim inttype As Type = GetType(Integer)
’ Returns the System.RuntimeType object representing the Project1.Type1 class.
DimmytypeAsType = GetType(Project1.Type1)
.NET Reflection can be used to get hold of non-Public members of a class instance. The System.Type class provides various methods that allow you to access the fields/properties/methods for all defined types. Depending on the context, you can use either the typeof(class) operator or the Object.GetType() method to get hold of the System.Type object representing the particular type and then use that type object to access the required member information.
The following code shows how to use the Type.GetField() and FieldInfo.GetValue() methods to determine the value of the ’pasteIndex’ private field implemented by the Diagram.Controller class.
// In C#.NET// Use Reflection to access the this.ActiveDiagram.Controller object’s pasteIndex private member
Type typecontroller = typeof(Syncfusion.Windows.Forms.Diagram.Controller);
System.Reflection.FieldInfo finfo = typecontroller.GetField('pasteIndex', BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.GetField);
int npasteindex = 0;
if(finfo != null)
npasteindex = (int)finfo.GetValue(this.ActiveDiagram.Controller);
’ In VB.NET
’ Use Reflection toaccess the Me.ActiveDiagram.Controller object’s pasteIndex privatemember
Dim typecontroller AsType = GetType(Syncfusion.Windows.Forms.Diagram.Controller)
Dim finfo As FieldInfo = typecontroller.GetType().GetField('pasteIndex', BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.GetField)
Dim npasteindex AsInteger = 0IfNot finfo IsNothingThen
npasteindex = finfo.GetValue(Me.ActiveDiagram.Controller)
EndIf
For example, the ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705’ dir for the 1.0 framework version.
You can do so using PInvoke to call this native API method:
[C#]
[DllImport('mscoree.dll')]
// DeclarationinternalstaticexternvoidGetCORSystemDirectory([MarshalAs(UnmanagedType.LPTStr)]System.Text.StringBuilder Buffer,
int BufferLength, refint Length);
// Gets the path to the Framework directory.
System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
int size;
// returned value in size can be ignored
GetCORSystemDirectory(sb, sb.Capacity, ref size);
[VB.Net]
’ Declaration
Private DeclareFunction GetCORSystemDirectory Lib 'mscoree.dll' ( ByVal Buffer As System.Text.StringBuilder, ByVal BufferLength AsInteger, ByRef LengthAsInteger) AsInteger
’ Gets the pathto the Framework directory.
Dim PathAsNew System.Text.StringBuilder(1024)
Dim SizeAsInteger
’ returned valueinSize can be ignored
GetCORSystemDirectory(Path, Path.Capacity, Size)
You can do so using the System.Diagnostics.Process.Start method as follows:
// Just specifying the document name will open the appropriate app based on system settings.Process.Start('Http://msdn.microsoft.com')
// Open a word document in Word.Process.Start('AWordDocument.doc')
// Or open the app directly:Process.Start()
The version information needs to be set with the ‘AssemblyVersion’ attribute for each project. However, this attribute does not need to be specified in the project’s AssemblyInfo file. You can create a separate file with the ‘AssemblyVersion’ attribute that is shared across projects that you wish to keep in sync. This file can either be shared via VSS, or by including the file as a link in the projects.
Make sure to preface the method/property name with the fully qualified interface name that it belongs to, like this:
// In C#// Where someType implements ISomeInterface’s SomeMethod as a private implementation.
Type someType = someInstance.GetType();
MethodInfo mi = someType.GetMethod('System.Windows.Forms.ISomeInterface.SomeMethod',
BindingFlags.NonPublic | BindingFlags.Instance);
if(mi != null)
{
mi.Invoke(someInsance, newobject[]{});
}
’ In VB.Net
’ Where someType implements ISomeInterface’s SomeMethod as a private implementation.
Dim someType As Type = someInstance.GetType()
MethodInfo mi = someType.GetMethod('System.Windows.Forms.ISomeInterface.SomeMethod',
BindingFlags.NonPublic | BindingFlags.Instance)
If Not mi Is Nothing Then
’ Assuming no arguments for SomeMethod.
mi.Invoke(someInsance, Nothing)
End If