Click here to Skip to main content
15,885,980 members
Articles / Programming Languages / XML
Article

XML Querying, Text Streaming, Debug Capture, and LDAP

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
17 Jan 20062 min read 26.7K   240   18  
Library containing functions for XML Querying, Text Streaming, Debug Capture and LDAP.

Image 1

Introduction

This GPCL (General Purpose Code Library) contains some general C# code functions that I use quite often. Please feel free to use the source code and implementation samples as freely as you like, and do not hesitate to tell me what you think of it.

Currently, it contains the following:

  1. XML-Querying capability. I am not aware of any easier and quicker way to query a regular XML file. If anyone of you knows of a better way, please add it to this library and let me know.
  2. Commonly used text streaming, file I/O functions.
  3. LDAP-Querying capability. You can authenticate credentials against an LDAP (Active Directory) server in just a few lines of code in any application you need to build in such integration.
  4. Send-To-Debug listener function. This function sends the supplied debug/error message, as well as the originating application name and function/procedure location within the code, to the Debug listener (same as Debug.WriteLine). A tool such as DebugView from Sysinternals can pick up its messages.

Using the code

Use the source code from GPCL_Source.zip as you like, for instance, by copying the functions into your own general purpose code library, or simply add the GPCL.dll as a reference to your project and start using its handy and easy (I hope!) functions in your code.

The source code as well as the demo project is thoroughly commented and explained within the code itself, so I'll just list two pieces of code as bait:

C#
//
// Remember to add a reference to the library
// in any applications you wish to use the library:
//
       using WernerReyneke.GPCL;
//
// Query XML - implementation example:
//

//Create an instance of the DataPlus class 
//in the WernerReyneke.GPCL namespace
WernerReyneke.GPCL.DataPlus xml_q = new DataPlus();
//Set a DataRow[] object equal to the QueryXML function
//The QueryXML function returns a DataRow[] object(set of data rows)
//By passing sCatalog= B as the value of 
//the where_criteria and * as the value of the sorting
//parameters,the data is filtered to return 
//only rows where sCatalog= B and is ordered
//Ascending according to theprimary key column
System.Data.DataRow[] drows = 
  xml_q.QueryXML("SampleXMLFile.XML","sCatalog='B'",
  "sShortText DESC","ipkPrimaryID");
//Loop through each row of data
foreach( DataRow r in drows )
{
    //Display the value of the sShortText column 
    //(see sample XML file: SampleXMLFile.XML 
    //in the \bin\Debug directory)
    MessageBox.Show(r["sShortText"].ToString());
}

The above code will query the XML file you provide, according to the where criteria and sorting order specified. The returned data is read back from a regular DataRow[] object.

C#
//
// LDAP Authentication - implementation example:
//
WernerReyneke.GPCL.LDAPPlus Auth = new LDAPPlus();
            
//provide the Active Directory Server Name, 
//NT username (your regular NT username
//and password you use to log on to your Windows Network
string name = Auth.Authenticate_Against_LDAP("LDAP (Active" + 
              " Directory Server) Name","NT username","password");

// The name variable will contain either failure info, or the valid
//name of the AD Server you're querying.
MessageBox.Show(name);

The above code will authenticate the credentials you pass against LDAP (Active Directory), and either return a failure message, or, in case of success, the valid name of the domain controller on AD. I recently developed a Web application for a large international petroleum company's Human Resources department, in ASP.NET, where the security/logon requirement was to integrate with Active directory (LDAP), so that no extra database of separate user accounts was necessary, but that the application use the existing users on Active Directory.

That's just two nice functions. Enjoy it, and all feedback is welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --