Wednesday, 6 September 2017

Kentico attachment using API



 // Create an instance of the Tree provider first
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        // Get the parent node - the API Example folder
        TreeNode parentNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/BoardPortal/LakeView-Board-Document", "en-us");    

  if (parentNode != null)
        {

 string filename = filename;
                string file = System.Web.HttpContext.Current.Server.MapPath(@"/LVRedseign/media/Document Repository/" + filename + "");
                //InsertFieldAttachment(parentNode, file);
                AttachmentInfo attachment = null;
                attachment = DocumentHelper.AddAttachment(newNode, "MenuItemTeaserImage", file, tree);
                attachment.AttachmentDocumentID = newNode.DocumentID;
                attachment.AttachmentExtension = ".pdf";
                attachment.AttachmentName = filename;
                attachment.AttachmentMimeType = "application/pdf";
                attachment.Insert();
              
}

No comments:

Post a Comment