Read the contents of a binary file and write to a Blob field in a new row of a table.
[C#]
/// <summary> /// Read the contents of a binary file and write to a Blob field in a new row of a table. /// </summary> /// <param name="string_Filename">A System.String that is the name of a binary file to read. Example: "C:\temp\myPicture.bmp"</param> /// <param name="table">An ITable interface that is the table is to have a new row added and have a specified BLOB field populated.</param> /// <param name="int32_BlobFieldIndex">A System.Int32 that is the index number of the Blob field in the Fields collection of the Table. Example: 3</param> /// <returns>True = successful. False = unscucceeful.</returns> /// <remarks></remarks> public System.Boolean WriteBlobFileContentsToTableRowField(System.String string_Filename, ESRI.ArcGIS.Geodatabase.ITable table, System.Int32 int32_BlobFieldIndex) { try { //Read the Blob (binary) stream from a file. ESRI.ArcGIS.esriSystem.IMemoryBlobStream memoryBlobStream = new ESRI.ArcGIS.esriSystem.MemoryBlobStreamClass(); memoryBlobStream.LoadFromFile(string_Filename); //Add a new row to the table ESRI.ArcGIS.Geodatabase.IRow row = table.CreateRow(); //Get the Blob Field from the Table. ESRI.ArcGIS.Geodatabase.IFields fields = row.Fields; ESRI.ArcGIS.Geodatabase.IField field = fields.get_Field(int32_BlobFieldIndex); //Test to ensure the index number specified is a Blob Field if (field.Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob) { //Write the Blob (binary) stream to the Blob Field and save row.set_Value(int32_BlobFieldIndex, (System.Object)memoryBlobStream); //row.get_Value(int32_BlobFieldIndex) = memoryBlobStream; row.Store(); //success return true; } else { //unsuccessful return false; } } catch (System.Exception ex) { //unsuccessful with error, interrogate more return false; } }
[Visual Basic .NET]
''' <summary> ''' Read the contents of a binary file and write to a Blob field in a new row of a table. ''' </summary> ''' <param name="string_Filename">A System.String that is the name of a binary file to read. Example: "C:\temp\myPicture.bmp"</param> ''' <param name="table">An ITable interface that is the table is to have a new row added and have a specified BLOB field populated.</param> ''' <param name="int32_BlobFieldIndex">A System.Int32 that is the index number of the Blob field in the Fields collection of the Table. Example: 3</param> ''' <returns>True = successful. False = unscucceeful.</returns> ''' <remarks></remarks> Public Function WriteBlobFileContentsToTableRowField(ByVal string_Filename As System.String, ByVal table As ESRI.ArcGIS.Geodatabase.ITable, ByVal int32_BlobFieldIndex As System.Int32) As System.Boolean Try 'Read the Blob (binary) stream from a file. Dim memoryBlobStream As ESRI.ArcGIS.esriSystem.IMemoryBlobStream = New ESRI.ArcGIS.esriSystem.MemoryBlobStreamClass memoryBlobStream.LoadFromFile(string_Filename) 'Add a new row to the table Dim row As ESRI.ArcGIS.Geodatabase.IRow = table.CreateRow 'Get the Blob Field from the Table. Dim fields As ESRI.ArcGIS.Geodatabase.IFields = row.Fields Dim field As ESRI.ArcGIS.Geodatabase.IField = fields.Field(int32_BlobFieldIndex) 'Test to ensure the index number specified is a Blob Field If field.Type = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob Then 'Write the Blob (binary) stream to the Blob Field and save row.Value(int32_BlobFieldIndex) = CType(memoryBlobStream, System.Object) ' Explicit Cast row.Store() 'success Return True Else 'unsuccessful Return False End If Catch ex As System.Exception 'unsuccessful with error, interrogate more Return False End Try End Function