Hi,
how to create a new document of particular document type is described here:
private bool CreateDocument()
{
// Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the parent node - the API Example folder
TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", "en-us");
if (parentNode != null)
{
// Create a new instance of the Tree node
TreeNode newNode = TreeNode.New("CMS.MenuItem", tree);
// Set the document's properties
newNode.DocumentName = "My new document";
newNode.DocumentCulture = "en-us";
// Insert the document into the content tree
newNode.Insert(parentNode);
return true;
}
return false;
}
And how to insert an image here:
private bool InsertUnsortedAttachment()
{
// Create a new instance of the Tree provider
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the document
TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", "en-us");
// Path to the file to be inserted. This example uses an explicitly defined file path. However, you can use an object of the HttpPostedFile type (uploaded via an upload control).
string postedFile = Server.MapPath("Files/file.png");
if (node != null)
{
// Insert the attachment
return (DocumentHelper.AddUnsortedAttachment(node, Guid.NewGuid(), postedFile, tree, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE, ImageHelper.AUTOSIZE) != null);
}
return false;
}
More API examples you can find on your Kentico installation:
http://<your_domain>/CMSAPIExamples/Default.aspx
Best regards,
Ivana Tomanickova