Posts

Showing posts with the label kentico 8

Sample code to check Kentico Xperience Object alternative form.

Kentico Xperience is a powerful CMS that build from asp.net framework. The CMS have an eCommerce solution, Intranet and collaboration, Online Marketing, and Content management that make Kentico Xperience is the most popular CMS nowadays. In Kentico Objects, you can create alternative forms allow you to create different versions of existing forms. The alternative forms can then be used instead of the default form in the system's administration interface or on the live site. This is the snippet for Kentico version 8.xx to check if the page type has an alternative form. Code Behind 1: public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) 2: { 3: bool haveForm = false; 4: if (classID != "") 5: { 6: if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) 7: { 8: var DataInfo = CMS.DocumentEngine.CMSD...

Kentico 8.xx - Snippet to check if page type have alternative form name

This is the snippet for Kentico version 8.xx to check if page type have alternative form. Code Behind public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) { bool haveForm = false; string strEditFormName = ValidationHelper.GetString(EditFormName, ""); if (classID != "") { if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) { var DataInfo = CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID); foreach (CMS.DataEngine.BaseInfo a in DataInfo) { string formName = ValidationHelper.GetString(a.GetValue("FormName"), ""); if (formName.Contains(strEditFormName)) { haveForm = true; break; } } ...

How to change the properties/method of one web part from within another web part - Kentico

This tutorial is to show how to access the web part properties/method from another web part. This situation basically when you use a repeater name repeater1 and inside repeater transformation you call another User control/web part name repeater2 . Every time you trigger an event on the repeater2 (ie: click, change the value, etc), you want to refresh the repeater1 value. But you cannot access the properties/method directly. Code Behind repeater / repeater1 Override OnInit Event protected override void OnInit(EventArgs e) { RequestStockHelper.Add("repeater2", this); base.OnInit(e); } Code Behind UserControl / repeater2 Called ReloadData() from another webpart. protected void LinkButton1_Click(object sender, EventArgs e) { CMSAbstractWebPart webpart = RequestStockHelper.GetItem("repeater2") as CMSAbstractWebPart; if (webpart != null) { webpart.OnContentLoaded(); } ...

Force form control to failed validation in Kentico BizForm - Code Behind

This is an example to manually force stop the biz form from continue processing save data and show error message to the Field Form Control. Note this is just an example. You may use this approach to set very complex validation on the Field in BizForm. OnLoad Method protected override void OnLoad(EventArgs e) { viewBiz.OnAfterSave += viewBiz_OnAfterSave; viewBiz.OnBeforeSave += viewBiz_OnBeforeSave; base.OnLoad(e); } OnBeforeSave Method void viewBiz_OnBeforeSave(object sender, EventArgs e) { //get the field form controller FormEngineUserControl fieldFormController = viewBiz.FieldControls["<field name>"]; if (fieldFormController != null) { //do custom validation - example fieldFormControl dont have text "*" if (!fieldFormController.Text.Contains("*")) { //stop biz form from continue processing viewBiz.StopProcessing = true; //focus the fiel...

Add search condition on Kentico smart search API

Below is an example of using the Smart Search API module in Kentico. The API Example inside Kentico not telling this, but I was able to figure out the way.  Kindly have a try on the snippet example  Smart Search Module API - Search With Condition  public void SmartSearchWithCondition(string searchText,string ClassName,string extraCondition) { DocumentSearchCondition docCondition = new DocumentSearchCondition(); docCondition.ClassNames = ClassName; docCondition.Culture = "en-US"; //refer https://docs.kentico.com/display/K82/Smart+search+syntax for the extra condition syntax var condition = new SearchCondition(extraCondition, SearchModeEnum.AllWords, SearchOptionsEnum.FullSearch, docCondition, true); searchText = SearchSyntaxHelper.CombineSearchCondition(searchText, condition); // Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("SearchIndex"); if (index != null) ...

Send email in Kentico 8.xx

This is an example method to send data in Kentico 8.xx Send email method using CMS.EmailEngine; using CMS.EventLog; ::: ::: public static class CustomClass {     public static void SendEmail(string EmailTemplateCode, MacroResolver mcr,string recipients)     {         EmailMessage msg = new CMS.EmailEngine.EmailMessage();         EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate(EmailTemplateCode, SiteContext.CurrentSiteID);                msg.EmailFormat = EmailFormatEnum.Both;         msg.From = eti.TemplateFrom;         msg.Recipients = recipients;         msg.Subject = eti.TemplateSubject;         try         {    ...

Turn off EventLogProvider from store update/delete/insert activity in Kentico

The event log stores information about all events that occur in the system. It is useful to view logged information if unwanted behavior occurs in the system and you want to find out where the problem originates or get additional details. But, some activities you don't want to be stored in the database while you are developing a custom web part. This is the way how to turn off the for a while in your custom code block. Step by Step  Add "using CMS.Base;" Wrap your code block with this using block code. using (CMSActionContext ctx = new CMSActionContext())     {         ctx.LogEvents = false;        //your action here. } So anything code you put under the comment " Your action " will not be recorded in the Event Log table. Have a try.

Kentico 8.1 - Custom Upload Form Control [Solved to support custom table to store image/binary stream data]

Kentico is a powerful CMS engine that allow you to developed portal very fast. But when you have a really big data such as (10,000 above), you may need to think a different way to store the data(Not put all document as a Page Menu Item). I have heard kentico have test their product for 100K document. But from my experience using shared server, it is cause a lot of painful if you want to expand the node in your page module, and even very slow to load the data.(That is my situation). So after all, I have decided to developed a " Custom Upload FormControl " to make Custom table support for upload files/media. This implementation is quite tricky because the custom formcontrol just store link to custom table field and it will store the image into media library folder. Look at the flow below : User/admin upload image using custom formcontrol Custom formcontrol check folder in media library, if not exist, create media library folder.(Each user will have their own folder so in future...

How to specify WhereCondition in Transformation - Nested Control - kentico 8, 7, 6

Image
Before this i wonder how to pass some where condition in transformation repeater. So i ask the kentico guys and he give me a solution which i think i can share to the others. So in your transformation you can specify the <script runat="server"></script> element. This is where you can pass the where condition. Let see the example : Transformation Code <cms:queryrepeater id="repItems" ... DelayedLoading="true" ... /> <script runat="server"> protected void Page_PreRender(object sender, EventArgs e) { queryrepeater.WhereCondition= "NodeAliasPath LIKE '"+(string)Eval("NodeAliasPath")+"'"; queryrepeater.ReloadData(true); } </script> Note : queryrepeater dont have DelayedLoading properties, use DataBindByDefault="false" instead. By Mohd Zulkamal NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites...