Hi Russel,
I'm not the original poster, but I will state that the functionality that you have described would be very useful. I'd like to be able to attach documents to a file geodatabase feature class using ArcToolbox tools or python scripts. My ultimate goal is to expose the attach file functionality through a geoprocessing service in ArcGIS Server. That way, users could add attachments to features by way of a web mapping application. This can currently be done very easily if your data is in SDE. I'd like to use a file geodatabase for my applications...
Dim pApplication As IApplication Dim pMxDocument As IMxDocument Dim pFeatLayer As IFeatureLayer Dim pFeatureclass As IFeatureClass Dim pTable As ITable Dim pContentsView As IContentsView3 Dim pfeature As IFeature Dim pFeatCursor As IFeatureCursor Dim OID As Integer Dim filepath As String pApplication = m_application pMxDocument = pApplication.Document pContentsView = pMxDocument.CurrentContentsView Dim selectedItem As System.Object = pContentsView.SelectedItem If Not (TypeOf selectedItem Is ESRI.ArcGIS.Carto.ILayer) Then Return End If Dim layer As ESRI.ArcGIS.Carto.ILayer = TryCast(selectedItem, ESRI.ArcGIS.Carto.ILayer) pFeatLayer = TryCast(layer, ESRI.ArcGIS.Carto.FeatureLayer) pFeatureclass = pFeatLayer.FeatureClass Dim tableAttachments As ITableAttachments = CType(pFeatureclass, ITableAttachments) Dim attachmentManager As IAttachmentManager = tableAttachments.AttachmentManager pTable = pFeatLayer pFeatCursor = pFeatureclass.Search(Nothing, False) pfeature = pFeatCursor.NextFeature() Do While Not pfeature Is Nothing OID = pfeature.OID filepath = pfeature.Value(pfeature.Fields.FindField("FilePath")) 'the field where you store the filename If Not filepath.Equals("999") Then ' Open a file as a memory blob stream. Dim memoryBlobStream As IMemoryBlobStream = New MemoryBlobStreamClass() memoryBlobStream.LoadFromFile(filepath) ' Create an attachment. Dim attachment As IAttachment = New AttachmentClass With _ { _ .ContentType = "image/jpeg", _ .Data = memoryBlobStream, _ .Name = filepath _ } ' Assign the attachment to the feature with ObjectID (OID) = 1. attachmentManager.AddAttachment(OID, attachment) pfeature.Store() pfeature = pFeatCursor.NextFeature Else pfeature = pFeatCursor.NextFeature() End If Loop pFeatCursor = Nothing
I was challenged with the same issue, so here's some psuedo code that may help. Using the active layer, in an Edit session, this code will loop through a featureclass reading a value from a Filepath field. Most people already have a column like this in their data, particularly if they use Hyperlinks. If the filepath value is not null, the associated file is loaded as an attachment for that feature.
Dim pApplication As IApplication Dim pMxDocument As IMxDocument Dim pFeatLayer As IFeatureLayer Dim pFeatureclass As IFeatureClass Dim pTable As ITable Dim pContentsView As IContentsView3 Dim pfeature As IFeature Dim pFeatCursor As IFeatureCursor Dim OID As Integer Dim filepath As String pApplication = m_application pMxDocument = pApplication.Document pContentsView = pMxDocument.CurrentContentsView Dim selectedItem As System.Object = pContentsView.SelectedItem If Not (TypeOf selectedItem Is ESRI.ArcGIS.Carto.ILayer) Then Return End If Dim layer As ESRI.ArcGIS.Carto.ILayer = TryCast(selectedItem, ESRI.ArcGIS.Carto.ILayer) pFeatLayer = TryCast(layer, ESRI.ArcGIS.Carto.FeatureLayer) pFeatureclass = pFeatLayer.FeatureClass Dim tableAttachments As ITableAttachments = CType(pFeatureclass, ITableAttachments) Dim attachmentManager As IAttachmentManager = tableAttachments.AttachmentManager pTable = pFeatLayer pFeatCursor = pFeatureclass.Search(Nothing, False) pfeature = pFeatCursor.NextFeature() Do While Not pfeature Is Nothing OID = pfeature.OID filepath = pfeature.Value(pfeature.Fields.FindField("FilePath")) 'the field where you store the filename If Not filepath.Equals("999") Then ' Open a file as a memory blob stream. Dim memoryBlobStream As IMemoryBlobStream = New MemoryBlobStreamClass() memoryBlobStream.LoadFromFile(filepath) ' Create an attachment. Dim attachment As IAttachment = New AttachmentClass With _ { _ .ContentType = "image/jpeg", _ .Data = memoryBlobStream, _ .Name = filepath _ } ' Assign the attachment to the feature with ObjectID (OID) = 1. attachmentManager.AddAttachment(OID, attachment) pfeature.Store() pfeature = pFeatCursor.NextFeature Else pfeature = pFeatCursor.NextFeature() End If Loop pFeatCursor = Nothing
Richard,
In the next release of ArcGIS we are looking at adding a geoprocessing tool that would give you the ability to use a key field to match a record in your table/feature class with a file stored on disk.
For example if you had a feature class containing sign posts with a photoID of 'sign1234' and you had a photo on disk named 'sign1234.jpg' you could attach photos based on this type of relationship.
Would these tools be useful with the way your data is currently stored?
Yes thats it! that would be perfect! Please hurry as this would be Indispensable to me!. Many thanks!
Instead of attaching the actual document to each feature and storing it in the geodatabase, is it possible to only store the LINK or PATH to the file in the geodatabase?
I have a street feature class that i am attaching hundreds of as built .pdf documents to. Because the geodatabase stores the actual file..it is getting very large very quickly. And it's redundant because the files are already stored on the server. The attachment feature is key because many of our users have arcgisexplorer and can view the documents as html pop ups from there. However, I am running out of space!
Each street segment has a unique segment number but the as built documents are randomly numbered. I have an access table that stores the segment number and it associated "asbuilt ID's" but they are not the same number.
It would be VERY useful if we could just attach several "hyperlinks" to a feature and have those links stored in the geodatabase.
Is this currently possbile or will it be in future releases?
And I hope this makes sense to all of you 🙂
Richard,
In the next release of ArcGIS we are looking at adding a geoprocessing tool that would give you the ability to use a key field to match a record in your table/feature class with a file stored on disk.
For example if you had a feature class containing sign posts with a photoID of 'sign1234' and you had a photo on disk named 'sign1234.jpg' you could attach photos based on this type of relationship.
Would these tools be useful with the way your data is currently stored?