Creating CMS.Files and uploading files to it using Code

mun yung kan asked on February 12, 2016 10:11

hey guys.

is there a programmatic way to create and CMS.File and add a file to its file upload field using code through a scheduled task?

Correct Answer

Pavel Jiřík answered on February 29, 2016 14:59

Hi,

Have you checked API examples in our documentation? An API example of attaching a file to a page field can be found here: https://docs.kentico.com/display/API9/Attachments#Attachments-Insertingattachmentsintopagefields

1 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on February 12, 2016 14:26

CMS.File is just one of page types, so yes, it is possible to create it in code behind. See example: https://docs.kentico.com/display/API9/Pages#Pages-Creatingpagesinasite'scontenttree

The challenge with CMS.File is that you have to upload actual file, which usually user specifies. So in your case this file should already be on server and you'll have to figure it's path/name on the fly.

0 votesVote for this answer Mark as a Correct answer

mun yung kan answered on February 15, 2016 03:49

Don't have problems creating the documents in the content tree.

Struggling to upload the files though. cant seem to find an example of how to do this in code behind.

0 votesVote for this answer Mark as a Correct answer

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