Thursday, June 27, 2019

Episerver CMS Content/Block Type Property Delete

When you work on Episerver site, some times, you have an experience that removed properties from content type or block type are still displayed on the CMS.
In the code, you have already removed them. But still, properties are showed in the CMS.
You wonder how you can remove deleted properties from content type or block.

You can easily remove those properties from the cms as following.

1.0 Logging to the cms.

2.0 Go to CMS-->Admin-->Content  Types.
All the content types and related properties are listed here.

3.0 You can see the missing tag as in the image.












4.0 Click on the property and Delete it.


Thursday, October 18, 2018

GIT Branches

Found good article
https://nvie.com/posts/a-successful-git-branching-model/

Wednesday, May 24, 2017

How to Use Excel to Create SQL Query String

Have you ever faced some situations where your database table's data are get updated or changed?

You have a backup database. You know you can use a backup database table to update the previous table data. But it takes more time to write update statement for each row.

You can use excel file to do that task easily as follow.

1.0 Generate the script from backup database. For example, I need to update 'is billable' columns of administrator table.
I write this query to get back up data.

SELECT aid,aisBillable FROM Administrator



2.0 Copy and Paste those query result into new excel file.



3.0  Use below SQL update function in the first row of the excel sheet as in the below image.
SQL:
="UPDATE Administrator set aisBillable ="&B2&" WHERE aid="&A2



4.0 Drag the first row to bottom rows. Then SQL 'Update' statement is updated as in the image.



5.0 You can copy those update queries and run on the SQL server to get updated table data.




Summary
Without writing an update/delete queries for each row, you can use excel functionality to make a job easier.







Sunday, May 14, 2017

Dot Net Bulk Insert

I have a project to get read CSV files and pushed those data to SQL table. CSV file contains more than 5000 records.

It is not good practice to insert record one by one SQL table due to it is a time-consuming process.

To optimize the process, Dot net has an ‘SQLBulkCopy’ feature to insert data at once to target table.

I like to share my experience how I used above feature.

1.0   I have read a CSV file and put them to object list.

2.0   For a bulk update, you need to convert object list to a data table.

Code for converting object list to the data table.
   public static DataTable ToDataTable<T>(List<T> items)
   {            DataTable dataTable = new DataTable(typeof(T).Name);
             //Get all the properties            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {                //Defining type of data column gives proper data table
                var type = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
                //Setting column names as Property names                dataTable.Columns.Add(prop.Name, type);            }            foreach (T item in items)
            {                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {                    //inserting property values to datatable rows                    values[i] = Props[i].GetValue(item, null);
                }                dataTable.Rows.Add(values); 
 }     
     //put a breakpoint here and check datatable 
return dataTable;
 }

2.1 You can call above method as below.

  DataTable dt = new DataTable("MyTable");
  dt = BaseDao.ToDataTable<T>(items);


3.0   After you need to specify the destination table. if source table and destination table’s column fields a are not match then you need to specify mapping columns.

4.0   Completed code is below.

protected override void BulkInsertData<T>(List<T> items)
 {  string connectionString = BaseDao.ConnectionString;
             DataTable dt = new DataTable("MyTable");
            dt = BaseDao.ToDataTable<T>(items);
  using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString))
  {
 
bulkCopy.BulkCopyTimeout = 660;   


bulkCopy.DestinationTableName = "Workday_Employee";


// Set up the column mappings by name.                SqlBulkCopyColumnMapping mapID = new SqlBulkCopyColumnMapping("Employee_ID", "Workday_Id");bulkCopy.ColumnMappings.Add(mapID);    
SqlBulkCopyColumnMapping mapID1 = new SqlBulkCopyColumnMapping("User_Name", "Username");bulkCopy.ColumnMappings.Add(mapID1);     
bulkCopy.WriteToServer(dt);
      bulkCopy.Close();         
}


Summary


Monday, April 3, 2017

URL Redirections - ASP.NET Sites



If your site is hosted on IIS server , you can  do the re-directions as below.

1.0 Add URLs as below to web config file . 

 
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

 <location path="home/about-us/meet-the-team/stephanie-brennan">
      <system.webServer>
        <httpRedirect enabled="true" destination="https://www.ibuynew.com.au/home/about-us/meet-the-team" httpResponseStatus="Permanent" exactDestination="true" />
      </system.webServer>
    </location>
 <location path="home/about-us/meet-the-team/nicholas-de-la-paz">
      <system.webServer>
        <httpRedirect enabled="true" destination="https://www.ibuynew.com.au/home/about-us/meet-the-team" httpResponseStatus="Permanent" exactDestination="true" />
      </system.webServer>
    </location>

</configuration>

2.0 Make sure to remove back slash, after the path property.
 Otherwise site won't work.
 <location path="home/about-us/meet-the-team/stephanie-brennan">





Tuesday, June 14, 2016

Minify and bundle CSS and JavaScript files for Kentico 7

Site performance can be checked through this site.  https://developers.google.com/speed/pagespeed, Some times it suggests us to bundle the CSS/ java scripts files.
But we cannot able to bundle CSS files in Kentico 7. When we tried to use dot net framework(4.5 and upper) features, Kentico gives DLL issues.
There are many solutions for PHP sites. But for asp net sites few solutions in the web. Among them, solution found in below site.
It has these DLLs.
 








1.0 Copy above highlighted DLLs to project bin
2.0 CMS master page –> edit layout page
add below codes to bundle the CSS files .
Make sure to use , <asp:placeholder>. Otherwise rendering issues will occurs in Kentico.

<%@ Import Namespace=”SquishIt.Framework” %>
<asp:PlaceHolder   runat=”server”>
<%= Bundle.Css()
.Add(“~/app_themes/ibuynew/style/viewport_1500.css”)
.Add(“~/app_themes/ibuynew/style/viewport_1280.css”)
.Add(“~/app_themes/ibuynew/style/viewport_1020.css”)
.Add(“~/app_themes/ibuynew/style/viewport_760.css”)
.Add(“~/app_themes/ibuynew/style/viewport_480.css”)
.Add(“~/app_themes/ibuynew/style/viewport_320.css”)
.Add(“~/app_themes/ibuynew/style/jquery.selectbox.css”)
.Add(“~/app_themes/ibuynew/style/colorbox.css”)
.Add(“~/app_themes/ibuynew/style/jquery.mCustomScrollbar.css”)
.Add(“~/app_themes/ibuynew/style/marketo.css”)
.Render(“~/app_themes/ibuynew/style/combined_#.css”)
%>
</asp:PlaceHolder>

Like wise you can add Js files to get bundle.

<asp:PlaceHolder   runat=”server”>
<%= Bundle.JavaScript()
.Add(“~/cmsscripts/ibuynew/socialmedia.js”)
.Add(“~/cmsscripts/ibuynew/ajax.js”)
.Add(“~/cmsscripts/jquery/jquery-core.js”)
.Add(“~/cmsscripts/jquery/jquery-cookie.js”)
.Add(“~/cmsscripts/jquery/jquery-tools.js”)
.Add(“~/cmsscripts/ibuynew/jquery.carouFredSel-6.2.0-packed.js”)
.Add(“~/cmsscripts/ibuynew/jquery.mCustomScrollbar.concat.min.js”)
.Add(“~/cmsscripts/ibuynew/jquery.ba-throttle-debounce.min.js”)
.Add(“~/cmsscripts/ibuynew/jquery.selectbox-0.2.js”)
.Add(“~/cmsscripts/ibuynew/css3-mediaqueries.js”)
.Add(“~/cmsscripts/ibuynew/jquery.colorbox-min.js”)
.Add(“~/cmsscripts/ibuynew/jquery.mCustomScrollbar.concat.min.js”)
.Add(“~/cmsscripts/ibuynew/form.js”)
.Add(“~/cmsscripts/ibuynew/common.js”)
.Render(“~/cmsscripts/ibuynew/combined_#.js”)
%>
</asp:PlaceHolder>

 Finally you can remove relevant CSS from kentico header.

Wednesday, November 11, 2015

Build Dot Net Project Without Installing Visual Studio By Using MS Build


Some situations we need to build dot net projects without installing visual studio in particular servers. To help such situations, we can use msbuild.exe. Following sections will explain using BAT file, how we can build the project.

1.0 set dot net framework path to environment variable.

To enable msbuild.exe in Command Prompt, you simply have to add .net framework path in the  environment variable of the machine.
You can access the environment variables by right clicking on 'Computer', click 'properties' and click 'Advanced system settings' on the left navigation bar. On the next dialog bog click 'Environment variables,' scroll down to 'PATH' and edit it to include your path to the framework (don't forget a ';' after the last entry in here.
For reference my path was C:\Windows\Microsoft.NET\Framework\v4.0.30319.

2.0 Bat file code
Open a note pad. Copy and paste below code and save extension as bat. Ex deploy.bat
Under  bat file code ,you need to give dot net project’s solution file path or project file path after ‘msbuild.exe’ depend on the requirement  as below.
‘pathMSBuild’ is denote dot net framework path
Code :

set pathMSBuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
@echo off
cls
cd %pathMSBuild%
msbuild.exe "D:\Netstarter -projects test R and  D\NIGEL\nigel\codePool\NigelSolution\NigelSolution.sln" /p:configuration=debug

pause



3.0 Every time you click BAT file , project will build in particular server location.