internal static DbaseFile CreateDbaseFile(String fileName, DataTable schema, CultureInfo culture, Encoding encoding, IGeometryFactory geoFactory) { DbaseFile file = new DbaseFile(fileName, geoFactory, false); Byte languageDriverCode = DbaseLocaleRegistry.GetLanguageDriverCode(culture, encoding); file._header = new DbaseHeader(languageDriverCode, DateTime.Now, 0); file._header.Columns = new List <DbaseField>(DbaseSchema.GetFields(schema, file._header)); file._headerIsParsed = true; file.Open(WriteAccess.Exclusive); file.Save(); file.Close(); return(file); }
internal void WriteFullHeader(DbaseHeader header) { _binaryWriter.Seek(0, SeekOrigin.Begin); _binaryWriter.Write(DbaseConstants.DbfVersionCode); UpdateHeader(header); _binaryWriter.Write(header.HeaderLength); _binaryWriter.Write(header.RecordLength); _binaryWriter.Write(new Byte[DbaseConstants.EncodingOffset - (Int32)_binaryWriter.BaseStream.Position]); _binaryWriter.Write(header.LanguageDriver); _binaryWriter.Write(new Byte[2]); foreach (DbaseField field in header.Columns) { String colName = field.ColumnName + new String('\0', DbaseConstants.FieldNameLength); Byte[] colNameBytes = Encoding.ASCII.GetBytes(colName.Substring(0, DbaseConstants.FieldNameLength)); _binaryWriter.Write(colNameBytes); Char fieldTypeCode = DbaseSchema.GetFieldTypeCode(field.DataType); _binaryWriter.Write(fieldTypeCode); _binaryWriter.Write(0); // Address field isn't supported if (fieldTypeCode == 'N' || fieldTypeCode == 'F') { _binaryWriter.Write((Byte)field.Length); _binaryWriter.Write(field.Decimals); } else { _binaryWriter.Write((Byte)field.Length); _binaryWriter.Write((Byte)(field.Length >> 8)); } _binaryWriter.Write(new Byte[14]); } _binaryWriter.Write(DbaseConstants.HeaderTerminator); }
private void parseHeader(Stream dbfStream) { _header = DbaseHeader.ParseDbfHeader(new NondisposingStream(dbfStream)); _baseTable = DbaseSchema.GetFeatureTableForFields(_header.Columns, _geoFactory); _headerIsParsed = true; }