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

Tuesday, 27 June 2017

Item count for Repeater Footer Template


 Below code for count item within footer template :

its working

<%# ((Repeater)Container.NamingContainer).Items.Count %>

Thursday, 6 August 2015

Display two decimal places, no rounding in javascript

Below example is working fine



        function round(num, decimals){
            if (!decimals) decimals = 2;
            var d = Math.pow(10,decimals);
            return (parseInt(num*d)/d).toFixed(decimals);
        };

This example is tested. I have using this on my application.

Tuesday, 11 March 2014

checkbox validation in asp.net using jquery

I am using below script for checkbox validation

Script

 var j = jQuery.noConflict();
j('form').submit(function (e) {
var cnt = $("input[name='chkItem']:checked").length;
if (cnt == 0) {              
j("#chkmessage").html("please checked atleast one");
return false;
}
});

html
<form>
Please select at least one checkbox<br/><br/>
<input type="checkbox" name="chkmessage" value="Test1" /> Test1<br/>
<input type="checkbox" name="chkmessage" value="Test2" /> Test2<br/>
<input type="checkbox" name="chkmessage" value="Test3" /> Test3<br/>
<input type="checkbox" name="chkmessage" value="Test4" /> Test4<br/>
<input type="checkbox" name="chkmessage" value="Test5" /> Test5<br/>
<br/>
<input type="button" id="btnSubmit" value="Submit" />
</form>

Thursday, 27 February 2014

Sql server rebuild index

When rebuild a index sql server lock the table to prevent database to any modification. Prevent this situation you can use "ONLINE" option. Index rebuild in three step. I am mention below

1. Preparation phase.
2. Build   
3. Final 
In  first phase collect all system metadata to create new structure of empty index. It is snapshot of table and row to provide transaction level read consistency and blocked all DML operation for short time.

Second phase all database record is scanned , merged, sorted and inserted into table.

And final phase, all uncommitted update transactions must be completed and all data modification is blocked for very short time until this is completed and system metadata is update and replace source object by the target.

You can use ALTER statement for rebuilding, but you need to pass index name one by one. So you can use below statement for update all indexes at a time

DECLARE @Database VARCHAR(255)   
DECLARE @Table VARCHAR(255)  
DECLARE @cmd NVARCHAR(500)  
DECLARE @fillfactor INT 

SET @fillfactor = 90 

DECLARE DatabaseCursor CURSOR FOR  
SELECT name FROM MASTER.dbo.sysdatabases   
WHERE name = 'TestTable'
ORDER BY 1  

OPEN DatabaseCursor  

FETCH NEXT FROM DatabaseCursor INTO @Database  
WHILE @@FETCH_STATUS = 0  
BEGIN  

   SET @cmd = 'DECLARE TableCursor CURSOR FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' + 
  table_name + '']'' as tableName FROM ' + @Database + '.INFORMATION_SCHEMA.TABLES 
  WHERE table_type = ''BASE TABLE'''   

   -- create table cursor  
   EXEC (@cmd)  
   OPEN TableCursor   

   FETCH NEXT FROM TableCursor INTO @Table   
   WHILE @@FETCH_STATUS = 0   
   BEGIN   

    IF (@@MICROSOFTVERSION / POWER(2, 24) >= 9)
       BEGIN
           -- SQL 2005 or higher command 
           SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' +CONVERT(VARCHAR(3),@fillfactor) + ')' 
           EXEC (@cmd) 
       END
    ELSE
    BEGIN
          -- SQL 2000 command 
          DBCC DBREINDEX(@Table,' ',@fillfactor)  
       END

    FETCH NEXT FROM TableCursor INTO @Table   
   END   

   CLOSE TableCursor   
   DEALLOCATE TableCursor  

   FETCH NEXT FROM DatabaseCursor INTO @Database  
END  
CLOSE DatabaseCursor   

DEALLOCATE DatabaseCursor

Check the result after index rebuild