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?
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
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?
Check this out from a settings standpoint:
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?
Please, sign in to be able to submit a new answer.