Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

What is reflection?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
idletask@msn.com - 24 Jun 2006 20:25 GMT
Can someone tell me what Reflection is? Specifically, what's the
System.Reflection class for?  I know that seems like a silly question
to some people here...

The reason is that I use a function that prints a printdoc object
directly to a file.  I tried getting my object to print to file
directly by setting the 'to file ' property, but it would never work.

Someone gave me code that works great for this purpose, and it's the
only part of my app that I dont fully understand.

Thanks
Barry Kelly - 24 Jun 2006 20:59 GMT
> Can someone tell me what Reflection is? Specifically, what's the
> System.Reflection class for?  I know that seems like a silly question
> to some people here...

System.Reflection is a namespace that contains many classes. The classes
in the System.Reflection namespace allow one to write very general
libraries that can manipulate types (i.e. get and set property values,
fields, call methods, instantiate types) without knowledge of the
specific types at compile-time.

It's called reflection because the types in the namespace reflect, or
represent, elements of the program itself. For example, a MethodInfo
object represents a method of an object.

> The reason is that I use a function that prints a printdoc object
> directly to a file.  I tried getting my object to print to file
> directly by setting the 'to file ' property, but it would never work.
>
> Someone gave me code that works great for this purpose, and it's the
> only part of my app that I dont fully understand.

It's hard to say what your code is doing if we can't see it.

-- Barry

Signature

http://barrkel.blogspot.com/

idletask@msn.com - 06 Jul 2006 04:17 GMT
Barry-
Sorry for the really late reply.

This is the code - I pass in the filename I want to save as and this
function takes the PrintDoc object and sends it to the printer as a
file.

I tried just setting the .PrintToFile property to true, but was not
able to get it to print to a file.

In my printing process, I generate the printdoc object's contents
outside this print function as well as the printer settings and printer
name.  that stuff is pretty basic.  It's this 'reflection' stuff that I
am confused about.

   Public Sub PrintToFile(ByVal Filename As String, Optional ByVal
OverwriteFile As Boolean = True)

       PrintDoc.PrinterSettings.PrintToFile = True
       Dim type As System.Type =
GetType(System.Drawing.Printing.PrinterSettings)
       Dim outputPort As System.Reflection.FieldInfo =
type.GetField("outputPort", Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance)
       outputPort.SetValue(PrintDoc.PrinterSettings, Filename)

       Dim printDialogDisplayed As System.Reflection.FieldInfo =
type.GetField("printDialogDisplayed", Reflection.BindingFlags.NonPublic
Or Reflection.BindingFlags.Instance)
       printDialogDisplayed.SetValue(PrintDoc.PrinterSettings, False)

       'now we have to ensure the path exists
       'if not, create it
       Dim DirectoryName As String = "C:\"
       System.IO.Path.GetDirectoryName(Filename)

       If Not System.IO.Directory.Exists(DirectoryName) Then
           System.IO.Directory.CreateDirectory(DirectoryName)
       End If

       If System.IO.File.Exists(Filename) And OverwriteFile Then
           System.IO.File.Delete(Filename)
       End If

       PrintDoc.Print()

   End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.