Accessing File Member Timestamps from a .NET C# Program
September 12, 2007 Hey, Mike
I’m trying to use C# .Net to inspect the file create date and file modified date on member files in a custom library under QSys.Lib. Do you have any idea how to do this or can you suggest a place to start? Unfortunately, I code in C# and do not know RPG or CL commands. –GS We can tackle this problem without any server side logic. Fortunately, this job is pretty easy, thanks to IBM providing us with integration into the Windows world. The first thing you need to learn about is a special program called NetServer, which can be used to publish IFS files with the Windows world in the same way that you can publish a folder on a Windows server as a share. In other words, you can map a Windows share to a portion or the entirety of the IFS. For more info on configuring NetServer, take a look at this article. You will need to decide at which level you want to publish your IFS information. This all depends on whether you need to access data in a single library, in multiple files, in a single file, etc. Since you want to review member information for a database file, you will need to look in the portion of the IFS that points to the traditional System i/AS/400 storage area. This section of the IFS is called QSYS.LIB. Some of the options are:
You might have guessed that you need to substitute the real library name for YOURLIB and the real file name for YOURFILE. Of course, the broader the share level the more information you expose to the outside world, so be as restrictive as possible. You will create a security maintenance headache if you try to maintain too many shares! On the other hand, don’t expect that you’ll be able to do much with /QSYS.LIB objects from the Windows world other than read some of their attributes! Once you publish the share to QSYS.LIB at the appropriate level using NetServer, make sure Windows can access the share so that it is available in your program (either through a mapped drive or via connecting to the share programmatically). Now for the sample. Say we create a share to a source file and call the share QSOURCEFILE on system MYAS400. The UNC path to our share is: myas400qsourcefile (In the AS/400 world, a database file or source file can have multiple members. When mapped to a Windows share, each AS/400 file appears as a folder and each member within the file appears as a Windows type file with an extension of .MBR.) Figure 1 shows what a source file containing two source members (Q1 and Q2) looks like when published as a Windows share.
Once Windows is connected to the IFS share, try out this simple C# console program, which reads through a source file and retrieves the creation time and modification time of each source member. using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] files = Directory.GetFiles( @"myas400qsourcefile", "*.*"); foreach (string file in files) { Console.WriteLine(file + " " + File.GetCreationTime(file) + " "+ File.GetLastWriteTime(file)); } Console.WriteLine("Completed"); Console.ReadLine(); } } } Keep in mind that IFS access can be relatively slow, especially when retrieving creation and update information, so access it wisely! For those wondering about an alternative server side approach, one alternative would be an SQL Table function created in RPG that will return information about the IFS to the .NET client via an ODBC or managed provider call. As always, there is more than one way to skin a cat. RELATED STORY Admin Alert: Three Steps to Mapping iSeries Data to a Windows Network Drive
|