Archive for October, 2008

Iterate Over all Fields and Properties in an Object with vb.net

Good Morning. Yesterday I was going mad. I needed to get the extended properties (like subject, author etc) of a file but without adding a reference to any new components. If you know how to do this in 1.1 of the Framework I would love to hear from you.

Anyway continuing the same theme as most of this week, we want to iterate over all fields and properties of a an object. This is code for .NET Framework 2.0 or above. Make it a great day!

Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mlA As New MyLabel
        Dim value As Object
        Dim T As Type = mlA.GetType
        For Each pi As System.Reflection.PropertyInfo In T.GetProperties
            If pi.CanRead AndAlso pi.CanWrite Then
                value = pi.GetValue(mlA, Nothing)
                Debug.Print(pi.Name)
                If Not IsNothing(value) Then
                    Debug.Print(value.ToString)
                End If
                Debug.Print("--------------------")
            End If
        Next
        For Each fi As System.Reflection.FieldInfo In T.GetFields
            Debug.Print(fi.Name)
            value = fi.GetValue(mlA)
            If Not IsNothing(value) Then
                Debug.Print(value.ToString)
            End If
            Debug.Print("--------------------")
        Next
    End Sub
 
End Class
 
Public Class MyLabel
    Inherits Label
 
    Public ContainerDay1 As Integer
    Public ContainerDay2 As Integer
    Public ContainerDay3 As Integer
    Public ContainerDay4 As Integer
    Public ContainerDay5 As Integer
    ' ...
 
End Class
 
Advertisements

Leave a comment

Use Reflection to access Friend Function with vb.net

Good Morning! First let me throw a shout out to Brian K. Woytovich who has a very cool, real to life blog. I encourage you to visit and hear what he has to say.

My topic today is one that I have been meaning to blog about.. Like yesterday’s blog entry sometimes we need to find a better way to access methods and properties of classes without loops. So we want to access a friend function of another class by using reflection. So here it is and make it a great day.

Imports System.Reflection
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim tc As New TestClass()
        Dim tcSayHello As MethodInfo = tc.GetType().GetMethod("SayHello", _
                                                    BindingFlags.NonPublic Or BindingFlags.Instance)
        tcSayHello.Invoke(tc, Nothing)
 
        Dim tcGetMessage As MethodInfo = tc.GetType().GetMethod("GetMessage", _
                                                      BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim params() As Object = {"Kelly Martens"}
        MessageBox.Show(tcGetMessage.Invoke(tc, params))
 
    End Sub
End Class
 
==========================================================
 
Public Class TestClass
 
    Friend Sub SayHello()
        Console.WriteLine("Hello")
    End Sub
 
    Friend Function GetMessage(ByVal name As String) As String
        Return "Hello " & name
    End Function
 
End Class
 

Leave a comment

Specify a class property name with a string variable in vb.net

Good morning all. Well watching "The Shield" last night was not real fulfilling. Like Vic was really going to take Shane down in a parking lot of a hospital. Then there was Dutch doing his best from being seduced by a woman old enough to be his mother. For once, I admired Billings better than Dutch for his willingness to do something about the threat to his family. The good news is next week’s episode looks more promising.

You might be wondering what is up with yesterday’s posting. Well my plan is to take each namespace shown there and its classes therein and explore them in separate blog postings. Its a big undertaking but it will put some rhyme and reason to the things I post.

Of course today is not the day that will start due to a development in a project I am working on. 🙂

I was in a situation where I had an instance of a class called "employee". The properties of employee also happen to be the same as the database table called employee. I had one variable representing the table name and one representing the column name. The original plan was to loop through the columns of the table till I found a match with my employee class property and write the value once I found the right property. The problem was that every time a loop occurred a new database call was needing to be made which made the end result occur quite slowly. (I did not design the employee class. Actually the way they did it was really cool but how were they to know they were going to find themselves in this situation at the time?) So I had to find a way to make my column variable and the employee class properties be able to interact.

So here is how I did it.

First I changed the column variable to object type instead of string. One line of code then observations.

employee.GetType.GetProperty(columnname).GetValue(employee, Nothing)

1. The GetType(Employee) returns an instance of Type that represent the class "Employee".
2. GetProperty(columnname) on the Type object returned from step 1 gives me the PropertyInfo that represent the shared property Instance of type Employee.
3. GetValue() on the returned PropertyInfo from step 2 returns me the value of Employee.(columnname – what that propertys name is).

Anyway, make it a great day!

 

Leave a comment

.NET Framework 3.5 Commonly Used Types and Namespaces Part 1

Good morning. Woke up late and so it is.

This is here as much for me as for you. Sometimes I am somewhere where I don’t have a book handy. Here is a poster which won’t be here forever due to its size and the the namespace listing and MS links.

 Microsoft.Aspnet.Snapin

Contains classes that are necessary for the ASP.NET management console application to interact with the Microsoft Management Console (MMC).

Microsoft.Build.BuildEngine

Contains the classes that represent the MSBuild engine.

Microsoft.Build.Framework

Contains classes that make up the tasks, loggers, and events of MSBuild.

Microsoft.Build.Tasks

Contains the implementation of all tasks shipping with MSBuild.

Microsoft.Build.Tasks.Deployment.Bootstrapper

Contains classes used internally by MSBuild.

Microsoft.Build.Tasks.Deployment.ManifestUtilities

Contains classes used internally by MSBuild.

Microsoft.Build.Utilities

Provides helper classes that you can use to create your own MSBuild loggers and tasks.

Microsoft.Csharp

Contains classes that support compilation and code generation using the C# language.

Microsoft.JScript

Contains classes that support compilation and code generation using the JScript language.

Microsoft.SqlServer.Server

Contains classes that are specific to the integration of the Microsoft .NET Framework common language runtime (CLR) component into Microsoft SQL Server, and the SQL Server database engine process execution environment.

Microsoft.VisualBasic

Contains classes that support compilation and code generation using the Visual Basic language.

Microsoft.VisualBasic.ApplicationServices

Contains types that support the Visual Basic Application Model and provide access to application information.

Microsoft.VisualBasic.CompilerServices

Contains internal-use only types that support the Visual Basic compiler.

Microsoft.VisualBasic.Devices

Contains types that support the My objects related to devices in Visual Basic.

Microsoft.VisualBasic.FileIO

Contains types that support the My file system object in Visual Basic.

Microsoft.VisualBasic.Logging

Contains types that support the My logging objects in Visual Basic and provides a simple log listener that directs logging output to file.

Microsoft.VisualBasic.MyServices

Contains types that support My in Visual Basic.

Microsoft.VisualBasic.MyServices.Internal

Contains internal-use only types that support My in Visual Basic.

Microsoft.VisualBasic.Vsa

Microsoft.VisualC

Microsoft.Vsa

Contains interfaces that allow you to integrate script for the .NET Framework script engines into applications, and to compile and execute code at run time.

Microsoft.Vsa.Vb.CodeDOM

Microsoft.Win32

Provides two types of classes: those that handle events raised by the operating system and those that manipulate the system registry.

Microsoft.Win32.SafeHandles

Contains classes that are abstract derivations of safe handle classes that provide common functionality supporting file and operating system handles.

Microsoft.WindowsCE.Forms

Contains classes for developing Pocket PC and Smartphone Windows Forms applications using the .NET Compact Framework.

Microsoft.WindowsMobile.DirectX

Contains classes for developing DirectX applications on devices with the .NET Compact Framework. Requires a future release of Windows Mobile to run the applications.

Microsoft.WindowsMobile.DirectX.Direct3D

Contains classes for developing Direct3D applications on devices with the .NET Compact Framework. Requires a future release of Windows Mobile to run the applications.

Microsoft_VsaVb

System

Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. Other classes provide services supporting data type conversion, method parameter manipulation, mathematics, remote and local program invocation, application environment management, and supervision of managed and unmanaged applications.

System.CodeDom

Contains classes that can be used to represent the elements and structure of a source code document. These elements can be used to model the structure of a source code document that can be output as source code in a supported language using the functionality provided by the System.CodeDom.Compiler namespace.

System.CodeDom.Compiler

Contains types for managing the generation and compilation of source code in supported programming languages. Code generators can each produce source code in a particular programming language based on the structure of Code Document Object Model (CodeDOM) source code models consisting of elements provided by the System.CodeDom namespace.

System.Collections

Contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hashtables and dictionaries.

System.Collections.Generic

Contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.

System.Collections.ObjectModel

Contains classes that can be used as collections in the object model of a reusable library. Use these classes when properties or methods return collections.

System.Collections.Specialized

Contains specialized and strongly typed collections; for example, a linked list dictionary, a bit vector, and collections that contain only strings.

System.ComponentModel

Provides classes that are used to implement the run-time and design-time behavior of components and controls. This namespace includes the base classes and interfaces for implementing attributes and type converters, binding to data sources, and licensing components.

System.ComponentModel.Design

Contains classes that developers can use to build custom design-time behavior for components and user interfaces for configuring components at design time. The design time environment provides systems that enable developers to arrange components and configure their properties.

System.ComponentModel.Design.Data

Contains classes for implementing design-time behavior of data-related components.

System.ComponentModel.Design.Serialization

Provides types that support customization and control of serialization at design time.

System.Configuration

Contains the types that provide the programming model for handling configuration data.

System.Configuration.Assemblies

Contains classes that are used to configure an assembly.

System.Configuration.Install

Provides classes that allow you to write custom installers for your own components. The Installer class is the base class for all custom installers in the .NET Framework.

System.Configuration.Provider

Contains the base classes shared by both server and client applications to support a pluggable model to easily add or remove functionality.

System.Data

Contains classes that constitute most of the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.

System.Data.Common

Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.

System.Data.Design

Contains classes that can be used to generate a custom typed-dataset.

System.Data.Linq

Contains classes to access relational data as objects. DataContext and related classes can be used for Reading, Creating, Updating and Deleting objects mapped to a database using mapping specified as attributes in your object model or in a separate external XML file.

System.Data.Linq.Mapping

Provides programmatic access to mapping information used by LINQ to SQL.

System.Data.Odbc

Contains classes that encapsulate the .NET Framework Data Provider for ODBC. The .NET Framework Data Provider for ODBC describes a collection of classes used to access an ODBC data source in the managed space.

System.Data.OleDb

Contains classes that encapsulate the .NET Framework Data Provider for OLE DB. The .NET Framework Data Provider for OLE DB describes a collection of classes used to access an OLE DB data source in the managed space.

System.Data.OracleClient

Contains classes that encapsulate the .NET Framework Data Provider for Oracle. The .NET Framework Data Provider for Oracle describes a collection of classes used to access an Oracle data source in the managed space.

System.Data.Sql

Contains classes that support SQL Server-specific functionality. The API extensions in this class add to the .NET Framework Data Provider for SQL Server (System.Data.SqlClient).

System.Data.SqlClient

Contains classes that encapsulate the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.

System.Data.SqlServerCE

Describes a collection of classes that can be used to access a database in SQL Server CE from Windows CE-based devices in the managed environment. With this namespace you can create SQL Server CE databases on a device and also establish connections to SQL Server databases that are on a device or on a remote server.

System.Data.SqlTypes

Contains classes for native data types within SQL Server. These classes provide a faster alternative to other data types. Using the classes in this namespace helps prevent type conversion errors caused in situations where loss of precision could occur. Because other data types are converted to and from SqlTypes behind the scenes, explicitly creating and using objects within this namespace results in faster code as well.

System.Diagnostics

Provides classes that allow you to interact with system processes, event logs, and performance counters. This namespace also provides classes that allow you to debug your application and to trace the execution of your code. For more information, see the Trace and Debug classes.

System.Diagnostics.CodeAnalysis

Contains classes for interaction with code analysis tools. Code analysis tools are used to analyze code for conformance to coding conventions such as naming or security rules.

System.Diagnostics.Design

Contains classes that can be used to extend design-time support for application monitoring and instrumentation.

System.Diagnostics.SymbolStore

Provides classes that allow you to read and write debug symbol information, such as source line to Microsoft intermediate language (MSIL) maps. Compilers targeting the .NET Framework can store the debug symbol information into programmer’s database (PDB) files. Debuggers and code profiler tools can read the debug symbol information at run time.

System.DirectoryServices

Provides easy access to Active Directory from managed code. The namespace contains two component classes, DirectoryEntry and DirectorySearcher, which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the network’s size.

System.DirectoryServices.ActiveDirectory

Provides a high level abstraction object model that builds around Microsoft® Active Directory® directory service tasks. The Active Directory® directory service concepts such as forest, domain, site, subnet, partition and schema are part of the object model.

System.DirectoryServices.Protocols

Provides the methods defined in the Lightweight Directory Access Protocol (LDAP) version 3 (V3) and Directory Services Markup Language (DSML) version 2 (V2) standards.

System.Drawing

Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the System.Drawing.Drawing2D, System.Drawing.Imaging, and System.Drawing.Text namespaces.

System.Drawing.Design

Contains classes that extend design-time user interface (UI) logic and drawing. You can further extend this design-time functionality to create custom toolbox items, type-specific value editors that can edit and graphically represent values of their supported types, or type converters that can convert values between certain types. This namespace provides the basic frameworks for developing extensions to the design-time UI.

System.Drawing.Drawing2D

Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.

System.Drawing.Imaging

Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.

System.Drawing.Printing

Provides print-related services. Typically, you create a new instance of the PrintDocument class, set the properties that describe what to print, and call the Print method to actually print the document.

System.Drawing.Text

Provides advanced GDI+ typography functionality. Basic graphics functionality is provided by the System.Drawing namespace. The classes in this namespace allow users to create and use collections of fonts.

System.EnterpriseServices

Provides an important infrastructure for enterprise applications. COM+ provides a services architecture for component programming models deployed in an enterprise environment. This namespace provides .NET Framework objects with access to COM+ services, making the .NET Framework objects more practical for enterprise applications.

System.EnterpriseServices.CompensatingResourceManager

Provides classes that allow you to use a Compensating Resource Manager (CRM) in managed code. A CRM is a service provided by COM+ that enables you to include non-transactional objects in Microsoft Distributed Transaction Coordinator (DTC) transactions. Although CRMs do not provide the capabilities of a full resource manager, they do provide transactional atomicity (all-or-nothing behavior) and durability through the recovery log.

System.EnterpriseServices.Internal

Provides infrastructure support for COM+ services. The classes and interfaces in this namespace are specifically intended to support calls into System.EnterpriseServices from the unmanaged COM+ classes.

System.Globalization

Contains classes that define culture-related information, including the language, the country/region, the calendars in use, the format patterns for dates, currency, and numbers, and the sort order for strings. These classes are useful for writing globalized (internationalized) applications.

System.IO

Contains types that allow synchronous and asynchronous reading and writing on data streams and files.

System.IO.Compression

Contains classes that provide basic compression and decompression for streams.

System.IO.IsolatedStorage

Contains types that allow the creation and use of isolated stores. With these stores, you can read and write data that less trusted code cannot access and help prevent the exposure of sensitive information that can be saved elsewhere on the file system. Data is stored in compartments that are isolated by the current user and by the assembly in which the code exists.

System.IO.Ports

Contains classes that control serial ports, providing a framework for synchronous and event-driven I/O, access to pin and break states, access to serial driver properties, and enumerations for specifying port characteristics.

System.Linq

Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).

System.Linq.Expressions

Contains classes, interfaces and enumerations that enable language-level code expressions to be represented as objects in the form of expression trees.

System.Management

Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure.

System.Management.Instrumentation

Provides the classes necessary for instrumenting applications for management and exposing their management information and events through WMI to potential consumers. Consumers such as Microsoft Application Center or Microsoft Operations Manager can then manage your application easily, and monitoring and configuring of your application is available for administrator scripts or other applications, both managed as well as unmanaged.

System.Messaging

Provides classes that allow you to connect to, monitor, and administer message queues on the network and send, receive, or peek messages.

System.Messaging.Design

Contains classes that can be used to extend design-time support for System.Messaging classes.

Leave a comment

.NET Framework 3.5 Commonly Used Types and Namespaces Part 2

Good morning. Woke up late and so it is.

This is here as much for me as for you. Sometimes I am somewhere where I don’t have a book handy. Here is a poster which won’t be here forever due to its size and the the namespace listing and MS links.

 

System.Net

Provides a simple programming interface for many of the protocols used on networks today. The WebRequest and WebResponse classes form the basis of what are called pluggable protocols, an implementation of network services that enables you to develop applications that use Internet resources without worrying about the specific details of the individual protocols.

System.Net.Cache

Defines the types and enumerations used to define cache policies for resources obtained using the WebRequest and HttpWebRequest classes.

System.Net.Configuration

Contains classes that applications use to programmatically access and update configuration settings for the System.Net namespaces.

System.Net.Mail

Contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.

System.Net.Mime

Holds types that are used to represent Multipurpose Internet Mail Exchange (MIME) headers. These types are used with the types in the System.Net.Mail namespace to specify Content-Type, Content-Disposition and Content-transfer-Encoding headers when sending email using the SmtpClient class.

System.Net.NetworkInformation

Provides access to network traffic data, network address information, and notification of address changes for the local computer. The namespace also contains classes that implement the Ping utility. You can use Ping and related classes to check whether a computer is reachable across the network.

System.Net.Sockets

Provides a managed implementation of the Windows Sockets (Winsock) interface for developers who need to help control access to the network.

System.Reflection

Contains classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types.

System.Reflection.Emit

Contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk. The primary clients of these classes are script engines and compilers.

System.Resources

Provides classes and interfaces that allow developers to create, store, and manage various culture-specific resources used in an application.

System.Resources.Tools

Contains the StronglyTypedResourceBuilder class, which provides support for strongly-typed resources. Beginning with the .NET Framework version 2.0, this compile-time feature encapsulates access to resources by creating classes that contain a set of static read-only (get) properties, thus making it easier to consume resources.

System.Runtime

Contains advanced types that support diverse namespaces such as System, the Runtime namespaces, and the Security namespaces.

System.Runtime.ConstrainedExecution

Defines a set of types that enumerate and define a contract for reliability between the author of some code, and the developers who take a dependency on that code.

System.Runtime.Hosting

Contains advanced types that are used in application activation within application domains.

System.Runtime.CompilerServices

Provides functionality for compiler writers using managed code to specify attributes in metadata that affect the run-time behavior of the common language runtime. The classes in this namespace are for compiler writers use only.

System.Runtime.InteropServices

Provides a wide variety of members that support COM interop and platform invoke services. If you are unfamiliar with these services, see Interoperating with Unmanaged Code.

System.Runtime.InteropServices.ComTypes

Contains methods that are definitions of COM functions for managed code. These functions replace the now-obsolete UCOM* methods in the System.Runtime.InteropServices namespace.

System.Runtime.InteropServices.CustomMarshalers

Supports the .NET infrastructure and is not intended to be used directly from your code.

System.Runtime.InteropServices.Expando

Contains the IExpando interface which allows modification of an object by adding or removing its members.

System.Runtime.Remoting

Provides classes and interfaces that allow developers to create and configure distributed applications.

System.Runtime.Remoting.Activation

Provides classes and objects that support server and client activation of remote objects.

System.Runtime.Remoting.Channels

Contains classes that support and handle channels and channel sinks, which are used as the transport medium when a client calls a method on a remote object.

System.Runtime.Remoting.Channels.Http

Contains channels that use the HTTP protocol to transport messages and objects to and from remote locations. By default, the HTTP channels encode objects and method calls in SOAP format for transmission, but other encoding and decoding formatter sinks can be specified in the configuration properties of a channel.

System.Runtime.Remoting.Channels.Ipc

Defines a communication channel for remoting that uses the Interprocess Communication (IPC) system of the Windows operating system. Because it does not use network communication, the IPC channel is much faster than the HTTP and TCP channels, but it can only be used for communication between application domains on the same physical computer.

System.Runtime.Remoting.Channels.Tcp

Contains channels that use the TCP protocol to transport messages and objects to and from remote locations. By default, the TCP channels encode objects and method calls in binary format for transmission, but other encoding and decoding formatter sinks can be specified in the configuration properties of a channel.

System.Runtime.Remoting.Contexts

Contains objects that define the contexts all objects reside within. A context is an ordered sequence of properties that defines an environment for the objects within it. Contexts are created during the activation process for objects that are configured to require certain automatic services such synchronization, transactions, just-in-time (JIT) activation, security, and so on. Multiple objects can live inside a context.

System.Runtime.Remoting.Lifetime

Contains classes that manage the lifetime of remote objects. Traditionally, distributed garbage collection uses reference counts and pinging for control over the lifetime of objects. This works well when there are a few clients per service, but doesn’t scale well when there are thousands of clients per service. The remoting lifetime service associates a lease with each service, and deletes a service when its lease time expires. The lifetime service can take on the function of a traditional distributed garbage collector, and it also adjusts well when the numbers of clients per server increases.

System.Runtime.Remoting.Messaging

Contains classes used to create and remote messages. The remoting infrastructure uses messages to communicate with remote objects. Messages are used to transmit remote method calls, to activate remote objects, and to communicate information. A message object carries a set of named properties, including action identifiers, envoy information, and parameters.

System.Runtime.Remoting.Metadata

Contains classes and attributes that can be used to customize generation and processing of SOAP for objects and fields. The classes of this namespace can be used to indicate the SOAPAction, type output, XML element name, and the method XML namespace URI.

System.Runtime.Remoting.Metadata.W3cXsd2001

Contains the XML Schema Definition (XSD) defined by the World Wide Web Consortium (W3C) in 2001. The XML Schema Part2: Data types specification from W3C identifies format and behavior of various data types. This namespace contains wrapper classes for the data types that conform to the W3C specification. All date and time types conform to the ISO standards specification.

System.Runtime.Remoting.MetadataServices

Contains the classes used by the Soapsuds.exe command line tool and the user code to convert metadata to and from XML schema for the remoting infrastructure.

System.Runtime.Remoting.Proxies

Contains classes that control and provide functionality for proxies. A proxy is a local object that is an image of a remote object. Proxies enable clients to access objects across remoting boundaries.

System.Runtime.Remoting.Services

Contains service classes that provide functionality to the .NET Framework.

System.Runtime.Serialization

Contains classes that can be used for serializing and deserializing objects. Serialization is the process of converting an object or a graph of objects into a linear sequence of bytes for either storage or transmission to another location. Deserialization is the process of taking in stored information and recreating objects from it.

System.Runtime.Serialization.Formatters

Provides common enumerations, interfaces, and classes that are used by serialization formatters.

System.Runtime.Serialization.Formatters.Binary

Contains the BinaryFormatter class, which can be used to serialize and deserialize objects in binary format.

System.Runtime.Serialization.Formatters.Soap

Contains the SoapFormatter class, which can be used to serialize and deserialize objects in the SOAP format.

System.Security

Provides the underlying structure of the .NET Framework security system, including base classes for permissions.

System.Security.AccessControl

System.Security.Cryptography

Provides cryptographic services, including secure encoding and decoding of data, as well as many other operations, such as hashing, random number generation, and message authentication.

System.Security.Cryptography.Pkcs

Provides programming elements for Public Key Cryptography Standards (PKCS), including methods for signing data, exchanging keys, requesting certificates, public key encryption and decryption, and other security functions.

System.Security.Cryptography.X509Certificates

Contains the common language runtime implementation of the Authenticode X.509 v.3 certificate. This certificate is signed with a private key that uniquely and positively identifies the holder of the certificate.

System.Security.Cryptography.Xml

Contains classes to support the creation and validation of XML digital signatures. The classes in this namespace implement the World Wide Web Consortium Recommendation, "XML-Signature Syntax and Processing", described at http://www.w3.org/TR/xmldsig-core/.

System.Security.Permissions

Defines classes that control access to operations and resources based on policy.

System.Security.Policy

Contains code groups, membership conditions, and evidence. These three types of classes are used to create the rules applied by the .NET Framework security policy system. Evidence classes are the input to security policy and membership conditions are the switches; together these create policy statements and determine the granted permission set. Policy levels and code groups are the structure of the policy hierarchy. Code groups are the encapsulation of a rule and are arranged hierarchically in a policy level.

System.Security.Principal

Defines a principal object that represents the security context under which code is running.

System.ServiceProcess

Provides classes that allow you to implement, install, and control Windows service applications. Services are long-running executables that run without a user interface. Implementing a service involves inheriting from the ServiceBase class and defining specific behavior to process when start, stop, pause, and continue commands are passed in, as well as custom behavior and actions to take when the system shuts down.

System.Text

Contains classes representing ASCII, Unicode, UTF-7, and UTF-8 character encodings; abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats String objects without creating intermediate instances of String.

System.Text.RegularExpressions

Contains classes that provide access to the .NET Framework regular expression engine. The namespace provides regular expression functionality that can be used from any platform or language that runs within the Microsoft .NET Framework.

System.Threading

Provides classes and interfaces that enable multithreaded programming. In addition to classes for synchronizing thread activities and access to data (Mutex, Monitor, Interlocked, AutoResetEvent, and so on), this namespace includes a ThreadPool class that allows you to use a pool of system-supplied threads, and a Timer class that executes callback methods on thread pool threads.

System.Timers

Provides the Timer component, which allows you to raise an event on a specified interval.

System.Transactions

Contains classes that allow your code to participate in transactions. The classes support transactions with multiple, distributed participants, multiple phase notifications, and durable enlistments..

System.Transactions.Configuration

Contains classes that describe configuration options used by System.Transactions classes

System.Web

Supplies classes and interfaces that enable browser-server communication. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request, the HttpResponse class, which manages HTTP output to the client, and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control.

System.Web.Caching

Provides classes for caching frequently used data on the server. This includes the Cache class, a dictionary that allows you to store arbitrary data objects, such as hash tables and data sets. It also provides expiration functionality for those objects, and methods that allow you to add and remove the objects. You can also add the objects with a dependency upon other files or cache entries, and perform a callback to notify your application when an object is removed from the cache.

System.Web.Compilation

Contains classes for generating and compiling custom file types within the ASP.NET build environment.

System.Web.Configuration

Contains classes that are used to set up ASP.NET configuration.

System.Web.Handlers

Contains HTTP handler classes that process HTTP requests to a Web server.

System.Web.Hosting

Provides the functionality for hosting ASP.NET applications from managed applications outside of Microsoft Internet Information Services (IIS).

System.Web.Mail

The classes in this namespace are obsolete; use the classes in the System.Net.Mail namespace. Contains classes that enable you to construct and send messages using the CDOSYS message component. The mail message is delivered through either the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. The classes in this namespace can be used either from ASP.NET or from any managed application.

System.Web.Management

Contains classes and interfaces for managing and monitoring the health of Web applications.

System.Web.Mobile

Contains the core capabilities, including authentication and error-handling, required for building ASP.NET mobile Web applications.

System.Web.Profile

Contains classes that are used to implement the ASP.NET user profile in Web server applications.

System.Web.RegularExpressions

Provides regular expressions used to parse ASP.NET files. All members of the System.Web.RegularExpressions namespace are descendants of the Regex class.

System.Web.Security

Contains classes that are used to implement ASP.NET security in Web server applications.

System.Web.Services

Consists of the classes that enable you to create XML Web services using ASP.NET and XML Web service clients. XML Web services are applications that provide the ability to exchange messages in a loosely coupled environment using standard protocols such as HTTP, XML, XSD, SOAP, and WSDL. XML Web services enable the building of modular applications within and across companies in heterogeneous environments making them interoperable with a broad variety of implementations, platforms and devices. The SOAP-based XML messages of these applications can have well-defined (structured and typed), or loosely defined parts (using arbitrary XML). The ability of the messages to evolve over time without breaking the protocol is fundamental to the flexibility and robustness of XML Web services as a building block for the future of the Web.

System.Web.Services.Configuration

Consists of the classes that configure how XML Web services created using ASP.NET run.

System.Web.Services.Description

Consists of the classes that enable you to publicly describe an XML Web service by using the Web Services Description Language (WSDL). Each class in this namespace corresponds to a specific element in the WSDL specification, and the class hierarchy corresponds to the XML structure of a valid WSDL document.

System.Web.Services.Discovery

Consists of the classes that allow XML Web service clients to locate the available XML Web services on a Web server through a process called XML Web services Discovery.

System.Web.Services.Protocols

Consists of the classes that define the protocols used to transmit data across the wire during the communication between XML Web service clients and XML Web services created using ASP.NET.

System.Web.SessionState

Supplies classes and interfaces that enable storage of data specific to a single client within a Web application on the server. The session state data is used to give the client the appearance of a persistent connection with the application. State information can be stored within local process memory or, for Web farm configurations, out-of-process using either the ASP.NET State Service or a SQL Server database.

System.Web.UI

Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page. This namespace includes the Control class, which provides all controls, whether HTML, Web, or User controls, with a common set of functionality. It also includes the Page control, which is generated automatically whenever a request is made for a page in your Web application. Also provided are classes which provide the Web Forms Server Controls data binding functionality, the ability to save the view state of a given control or page, as well as parsing functionality for both programmable and literal controls.

System.Web.UI.Adapters

Contains the base classes for control adapters and page adapters, which you can use to override lifecycle states of pages and controls to modify their default markup or behavior for new markup standards or for specific browsers.

System.Web.UI.Design

Contains classes that can be used to extend design-time support for Web Forms and Web server controls.

System.Web.UI.Design.MobileControls

Obsolete. Contains classes that provide design-time support for the classes in the System.Web.UI.MobileControls namespace. The classes in this namespace are obsolete; use the classes in System.Web.UI.Design.WebControls instead.

System.Web.UI.Design.MobileControls.Converters

Contains classes that provide design-time support for data type converters in mobile controls.

System.Web.UI.Design.WebControls

Contains classes that can be used to extend design-time support for Web server controls.

System.Web.UI.Design.WebControls.WebParts

Contains classes that provide design-time support for controls derived from classes in the System.Web.UI.WebControls.WebParts namespace.

System.Web.UI.HtmlControls

Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.

System.Web.UI.MobileControls

Obsolete. Contains a set of ASP.NET server controls that can intelligently render your application for different mobile devices. The classes in this namespace are obsolete; use the controls in System.Web.UI.WebControls instead.

System.Web.UI.MobileControls.Adapters

Contains classes you can use to override lifecycle stages of a mobile control to modify its default HTML, CHTML, or WML markup or behavior for new markup standards or for specific browsers and mobile devices.

System.Web.UI.MobileControls.Adapters.XhtmlAdapters

Contains classes you can use to override lifecycle stages of a mobile control to modify its default XHTML markup or behavior for new markup standards or for specific browsers and mobile devices.

System.Web.UI.WebControls

Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.

System.Web.UI.WebControls.Adapters

Contains classes you can use to override lifecycle stages of a Web control to modify a control’s default markup or behavior for new markup standards or for specific browsers.

System.Web.UI.WebControls.WebParts

Contains an integrated set of classes and interfaces for creating Web pages whose appearance and behavior can be modified (personalized) by end users. The user-defined settings for each page are saved for future browser sessions.

System.Web.Util

Contains classes that enable callback methods to be run under the scope of a transaction and that enable work to be posted to separate threads.

System.Windows.Forms

Contains classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows operating system.

System.Windows.Forms.ComponentModel.Com2Interop

Contains helper classes that Visual Studio uses to display property pages while in design mode.

System.Windows.Forms.Design

Contains classes that support design-time configuration and behavior for Windows Forms components. These classes consist of: Designer classes that provide support for Windows Forms components, a set of design time services, UITypeEditor classes for configuring certain types of properties, and classes for importing ActiveX controls.

System.Windows.Forms.Design.Behavior

Contains classes for creating custom user interface behavior for components at design time.

System.Windows.Forms.Layout

Contains classes that support design-time and run-time layout behaviors.

System.Windows.Forms.PropertyGridInternal

Provides internal support for the PropertyGrid control. The classes in this namespace support the .NET Framework infrastructure and are not intended to be used directly from your code

System.Xml

Provides standards-based support for processing XML.

System.Xml.Schema

Contains the XML classes that provide standards-based support for XML Schemas definition language (XSD) schemas.

System.Xml.Serialization

Contains classes that are used to serialize objects into XML format documents or streams.

System.Xml.XPath

Contains the XPath parser and evaluation engine. It supports the W3C XML Path Language (XPath) Version 1.0 Recommendation (www.w3.org/TR/xpath).

System.Xml.Xsl

Provides support for Extensible Stylesheet Transformation (XSLT) transforms. It supports the W3C XSL Transformations (XSLT) Version 1.0 Recommendation (www.w3.org/TR/xslt).

System.Xml.Xsl.Runtime

Provides internal support for the classes in the System.Xml.Xsl namespace. The classes in this namespace support the .NET Framework infrastructure and are not intended to be used directly from your code.

Leave a comment

Write DataSet to a Microsoft Word Document with an Array using vb.net

Good Morning everyone! My weekend was not all that great on a personal level. I was pretty much down for the count with the flu all weekend. It seems when the seasons change it just hits me. But on a work level, I did well. I came up with the GUI design for the implementation of a Crystal Reports type interface allowing people to build templates for emails they send out. It may not sound like much but believe me, getting this part down was a huge step. The biggest challenge was finding a way to do everything we needed to do and yet conserve work space area in the document even for those with 800 x 600 monitors.

Anyway, this is a subject I think many developers would like to hear about. MS Word is extremely slow to automate. Their can be no dispute about this. Writing a huge amount of data to the document is a trying and perilous task. Unlike Excel so many things can go wrong.

What we want to do is write the dataset table to an array first, then write the array to a text string, place the text on the document at the required insertion point and then convert it to a table. It is not as fast as my sample doing this with Excel, but it is must faster than doing it cell by cell and is at least doable with vb.net and MS Word. This sample will work with any MS Word version except Word 97 and below and on any version of the .NET Framework.

Thanks and make it a great day!

‘Note vba is not zero based….

Dim rows As Integer = dsreport.Tables.Item(0).Rows.Count
Dim columns As Integer = dsreport.Tables.Item(0).Columns.Count

‘creating the array that will hold our data

Dim DataArray(rows, columns) As Object

‘writing the data to the array

For c = 0 To columns – 1
            DataArray(r, c) = dsreport.Tables(0).Columns.Item(c).ColumnName
            For r = 0 To rows – 1
                DataArray(r, c) = dsreport.Tables(0).Rows(r).Item(c)
            Next
        Next

‘creating a range at the Word Document insertion point

Dim oRange = oDoc.Content.Application.Selection.Range

‘creating a string to hold what is in our array
        Dim oTemp As String
        For r = 0 To rows – 1
            For c = 0 To columns – 1
                oTemp = oTemp & DataArray(r, c) & vbTab
            Next
        Next

‘writing the text to our document. It is not a table yet.
        oRange.Text = oTemp

‘convert it to a table using vba and you are done!

oRange.ConvertToTable(Separator:=wdSeparateByTabs, NumColumns:=dsreport.Tables(0).Columns.Count, _
NumRows:=dsreport.Tables(0).Rows.Count – 1, AutoFitBehavior:=wdAutoFitContent)

 

 

 

2 Comments

Verify Email Address is Valid with vb.net

Good morning. As of this writing, the stock market appears to be on the verge of a complete collapse today. They have already halted selling and the market has not even opened due to the fall the futures market has already taken. Watching my retirement fly out the window as my broker is telling me to sit tight is not an easy thing for me to do. I am a person that has trouble sitting idly by and doing nothing. But that is my own character defect.

Anyway, the task before me is simple yet needed. I want to verify that the user has actually entered a valid email address. We are checking to make sure it is in a format that is an email address, not whether or not it is a legitimate email address. we accomplish by using regular expressions. To be honest, the regular expressions subject torments me. I don’t care for it but it works here nicely.

Make it a great day!

Imports System.Text.RegularExpressions

Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
              Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
              Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
              If emailAddressMatch.Success Then
                  EmailAddressCheck = True
              Else
                  EmailAddressCheck = False
              End If
          End Function

 

Technorati Tags: ,,,,,,,,,,,,,

Windows Live Tags: address,vb.net,.NET Framework,csharp,Verify,Email,Valid,user,subject,System,Text,RegularExpressions,Match,Regex

 

Leave a comment