Does anyone know if it is possible to read random access files in C#?
I am trying to replicate the following function (from an old VB6 application) in C# -
Open File For Random Shared As #100 Len = Len(Record)
Get #100, DM, Record
Close #100
Public DM As Long
Public Record As DMrecord
Public Type DMrecord
column1 As Long
column2 As Integer
column3 As Integer
column4 As Integer
column5 As String * 4
End Type
EDIT -
I have now tried using the VisualBasic DLL as suggested below and receive the following error on the FileGetObject line -
"The best overloaded method match for Microsoft.VisualBasic.FileSystem.FileGetObject(int, ref object, long) has some invalid argument"
The code I am using is -
public class Record
{
public int DMtype;
public long ecn;
public Record(int DMtype, long ecn)
{
this.DMtype = DMtype;
this.ecn = ecn;
}
public Record()
{
}
}
string fileName = @"C:\RandomAccess.dat";
string returnString = string.Empty;
int row = 1;
int maxRow = 1000;
Record aFileRecord = new Record();
FileSystem.FileOpen(1, fileName, OpenMode.Random, OpenAccess.Read, OpenShare.LockRead);
while (row < maxRow)
{
//Get record 2 1st.>>
FileSystem.FileGetObject(1, aFileRecord, row);
returnString += aFileRecord.DMtype.ToString() + "$" + aFileRecord.ecn.ToString();
row++;
}
FileSystem.FileClose(1);
I have tried setting 'Record' as both a struct and a class and get the same error.
EDIT 22/08/13 - I never did get to the bottom of this, ended up exporting the random access data to comma seperated text files in VB6, then consuming the files in SSIS.