Weird Attachment Issue

Andre Pfanz asked on June 28, 2016 20:29

I'm on v9 of Kentico.

I'm trying to add an image to a file selection field called "UploadedImage". When I try, I get this in the file selection field with no image:

/CMSModules/Content/CMSDesk/Edit/593352F4-AF45-48BD-A09F-9EE015BEBE88

Here's my code I'm using to import:

var attachmentNode = TreeNode.New(FILE_PAGE_TYPE);
attachmentNode.DocumentName = Path.GetFileName(imagePath);
attachmentNode.DocumentCulture = galleryNode.DocumentCulture;
//Assign the filename
attachmentNode.SetValue("FileTitle", Path.GetFileName(imagePath));
DocumentHelper.InsertDocument(attachmentNode, galleryNode);
//Save the file into the attachment
AttachmentInfo newAttachment = DocumentHelper.AddUnsortedAttachment(attachmentNode, Guid.NewGuid(),         imagePath, treeProvider);
attachmentNode.SetValue("UploadedImage", newAttachment.AttachmentGUID);
DocumentHelper.UpdateDocument(attachmentNode);

I have to click the Select button and select the image from the Attachments tab to get anything to show up. However, I have thousands of images to import, so doing this manually is out of the question.

Does anyone know what I'm doing wrong here?

Recent Answers


Brenden Kehren answered on June 28, 2016 20:59 (last edited on June 28, 2016 21:03)

Check out this post, I have some code in there on how to properly update an attachment using the API.

Also make sure your field type is set to the proper type, which should be File

0 votesVote for this answer Mark as a Correct answer

Andre Pfanz answered on June 28, 2016 21:55

I checked the field type and found it is "Media selection" instead of just file. Do you know how to add an attachment for that using the API?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 29, 2016 01:10

Check this out from a settings standpoint:

Image Text

0 votesVote for this answer Mark as a Correct answer

Andre Pfanz answered on June 29, 2016 17:32

I see from the screenshot you have "Upload file" selected from the form control. On my site, "Media selection" is chosen. How do I use the API to upload a file into that form control?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.