Wednesday, 13 September 2017

Call resource strings in transformations

 

Using resource strings in transformations

ASCX Transformation :-

We can use below code

<%# Localize("{$stringKey$}") %>
Text / XML transformations – use localization macro expression string or we can use the GetResourceString method
{$stringKey$}
 

OR 

 {% GetResourceString("stringKey") %}
 

Call resource strings in the Kentico API

Kentico API provide ResHelper.GetString() class
string localizedResult = ResHelper.GetString("stringKey");

 

 

 

 

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();
              
}

Create Document In Kentico using API

private bool CreateDocument()
    {
        // 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");

        TreeNode nodeFile = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Board-Document-pdf", "en-us");

        if (parentNode != null)
        {
            DataTable dt = ReadCsvFile();
          
            foreach (DataRow dr in dt.Rows)
            {
                TreeNode newNode = TreeNode.New("custom.LakeView_Board_Document", tree);//CMS.MenuItem
                //Guid guid = Guid.NewGuid();
                newNode.NodeName = dr["DocumentTitle"].ToString();
                newNode.NodeGUID = Guid.NewGuid();
                //newNode.DocumentName = dr["DocumentTitle"].ToString();
                newNode.NodeAlias = dr["DocumentTitle"].ToString().Replace(" ", "-");             
                //newNode.DocumentCulture = "en-us";             
                newNode.SetValue("Title", dr["DocumentTitle"].ToString());
                newNode.SetValue("Description", dr["Description"].ToString());
                newNode.SetValue("DocumentDate", DateTime.ParseExact(dr["DocumentDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("IsBoard", Convert.ToBoolean(dr["IsBoard"]));
                newNode.SetValue("IsOperating", Convert.ToBoolean(dr["IsOperating"]));
                newNode.SetValue("DocumentTypes", dr["DocumentType"].ToString());
                newNode.SetValue("DocumentPath", dr["DocumentPath"].ToString());
                newNode.SetValue("CreatedDate", DateTime.ParseExact(dr["CreatedDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("StartDate", DateTime.ParseExact(dr["StartDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("EndDate", DateTime.ParseExact(dr["EndDate"].ToString(), "dd-MM-yyyy", null));
                //newNode.DocumentName = dr["DocumentTitle"].ToString();
                newNode.Insert(parentNode.NodeID);//parentNode
                //DocumentHelper.InsertDocument(newNode, parentNode.NodeID, tree);
                //  CMS.WorkflowEngine.DocumentHelper.InsertDocument(node, parent, tree);
                newNode.Publish();              
            }
            return true;
        }
        return false;
    }