Select to view content in your preferred language

Add attachment to a new feature

2707
3
11-28-2013 08:02 AM
SheridanNava
Occasional Contributor
How can i add atachment to a new feature?? in the documentation says

 Attachment attachment = new Attachment(featureSource, ID, "WaterMeter1.jpg");

but how to get the id if it is a new feature ???.  i need to add attchment on the same form .
0 Kudos
3 Replies
HemingZhu
Frequent Contributor
How can i add atachment to a new feature?? in the documentation says

 Attachment attachment = new Attachment(featureSource, ID, "WaterMeter1.jpg");

but how to get the id if it is a new feature ???.  i need to add attchment on the same form .


using the FeatureDataRow.Fid. Like this:

FeatureDataRow featureDataRow =featureDataTable.NewRow();
featureDataTable.Rows.Add(featureDataRow);
.
.
int oid =featureDataRow.Fid;
.
.
AttachmentManager manager =featureDataTable.FeatureSource.AttachmentManager;
Attachment attachment=New Attachment(featureDataTable.FeatureSource, oid, fileName);
.
.
if (manager.HasAttachment && manager.AllowEdits)
{
    manager.AddAttachment(attachment, fileSource, FileOperation.CopyFile);
}
0 Kudos
SheridanNava
Occasional Contributor
i try this. but i get this error. it means tha the id that you said is a temporary id  so it doesnt work to create attachments, i need to make this work with only one form, i wouldnt like have to create the feature and then selected to add the file.

[ATTACH=CONFIG]29721[/ATTACH]
0 Kudos
HemingZhu
Frequent Contributor
i try this. but i get this error. it means tha the id that you said is a temporary id  so it doesnt work to create attachments, i need to make this work with only one form, i wouldnt like have to create the feature and then selected to add the file.

[ATTACH=CONFIG]29721[/ATTACH]


The code i showed to you is one of the project i did. It add the new feature and attachments if user choose to attach files. it woked for me. You are right on the sense that you has to create the feature in the featuresource so you can have an tempory id (actually it is a negitive number) in the map cache for you to add attachment. But you can definitely created the user experience through the code that user don't feel that way....
0 Kudos