Posts

Showing posts from 2021

Unlock Full Rich Text Editor In Sitecore

Image
As Usual Sitecore Team not forget hidden gems, This blog will let you enable all hidden buttons in Sitecore RTE (Rich Text Editor) as per your requirements. Sitecore provide us with more than one profile in Core Database for RTE, I will show you each one with path in core Database: Profiles Path: "/sitecore/system/Settings/Html Editor Profiles" Profiles Types: There's four types of profiles for RTE  click on Images to view the full size Default IDE Medium Full How To Apply: Step 1: Create new config file Step 2: Add the following code to change the default RTE <sitecore> <settings>      <setting name="HtmlEditor.DefaultProfile" value="/sitecore/system/Settings/Html Editor Pr...

Sitecore Images ALT text

Image
As you know the Images in Sitecore uses Unversioned  template which uses the default language "en", but what if you need to use Alt Text in other languages, and you don't want to add the text for each language? I actually tried many things to do this 😰 my first solution was to make custom processor for uploading images and control the whole process, but this not worked for me as I was uploading images with alternative text from Item not from Media Library, unfortunately this not worked for me as the alt text was empty when uploading the images I made too much debugging to know Why!! and also did a reverse engineering on Sitecore.Kernel.dll through ILSpy  but nothing useful to me Then I tried to take a look at the templates of the Images, I found that all fields is Shared except the alt text and I remembered that all fields were filled with data while debugging except the alt Field Th...

Hidden things about Constructor in C#

Image
  What's constructor? It's a special method used to initialize an object or struct, limit access to object or control object or structs by set default values, In brief it's like the key to the door, let's say you want to run your car what do you need to do this? of sure you need the Key to run, so the Constructor in this case to run function of the Car has a Parameter called Key, without the Key you cannot run public class Car { string _key; public Car(string key){ // the constructor, accepts string key as parameter _key=key; } } Parameterless constructors: If you didn't create any constructors in your class, then C# creates the default P arameterless Constructor that initialize C# types default values, and the same on Structs, and if you have Static Fields then C# by default creates Static Constructor to initialize those Fields into default value   ...

Double VS Decimal In C#

Image
If you are using double or float in financial arithmetic operations, please stop ⛔  this !! the basic difference between double and decimal is that decimal and float is a numeric type with base 2 that means only number with base 2 are expressible in these types while in our daily basis we use numbers with base 10, 0-9 numbers Sample code: decimal dcm = 4m / 12m; // 0.3333333333333333333333333333 double dbl = 4.0 / 12.0;// 0.333333333333333 dcm + dcm + dcm + dcm + dcm + dcm; //1.9999999999999999999999999998 dbl + dbl + dbl + dbl + dbl + dbl; //2 As you can see in the upper code there's a rounding error,  the correct value should be 1.9  while in double it was 2 References: Microsoft

C# Integral Types That Lack Arithmetic Operations

Image
In C# there's some types that lack arithmetic operations These Integral types are 8 and 16 Bit so it's converted implicitly to the largest types, below is the list of these types : byte sbyte short ushort Sample of code: short a=10,b=10; short sum = a+b; // compile time error The solution: as mentioned a and b   variables   are implicitly  converted to the largest type "Int" , to solve this we have to use the explicit casting on the total result: short a=10,b=10; short sum = (short)(a+b); // compiled successfully References: Microsoft

C# Numeric types Overflow

Image
will this code be compiled? int x= int.MaxValue; x=x+1; The answer is, yes it will be compiled  I will tell you how, at runtime arithmetic operations on Integral types can overflow, and this happens silently no exceptions will be thrown, and the results exhibits wraparound behavior that means  int x= int.MaxValue; x= x+1; (x == int.MinValue) // True and if we do also the below expressions it will not give you the right result int a = 80000;  int b = 80000;  int c = a * b;  // 2105032704 while the right result is  6,400,000,000 So to avoid this issue we will use Checked Operator int a = 80000;  int b = 80000;  int c = checked(a * b);  // Run-time exception (line 9): Arithmetic operation resulted in an overflow Checked: The checked keyword is used to explicitly enable overflow checking for integral-type arithmetic ...

How to get Project Files From CMS in Sitecore 8+

Image
What if you want to browse / download some files for your CMS application and you don't have access on the server can we do this from CMS? Yes we can do 😃 There's more than one way to do this, I will mention two ways here: First way: Go to this URL : YourInstanceUrl/sitecore/shell/default.aspx?xmlcontrol=FileExplorer Note: In the versions prior to Sitecore 8 this link was in Desktop Module  In this way you can browse / delete / deploy any files you want Second way: Go to your CMS >> Desktop >> Development Tools >>  Package Designer >> Click on "Files Statically" >> You can choose the files you want in your package 

Convert JSON to C# Class In Visual Studio

Image
I was working on Integration with one of the social media This social media provider was returning me a big complex  JSON object I wanted to deserialize this object, and if I want to convert the JSON object into C# class then this will take sometime from me,  So I found a way to do this from Visual Studio,  follow me to know how to do it 👇 Sample JSON data: {"widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500 }, "image": { "src": "Images/Sun.png", "name": "sun1", "hOffset": 250, "vOffset": 250, "alignment": "center" }, "text": { "data": "Click Here", "size": 36, ...

How to delete/ move more than one item in Sitecore easily

Image
Sometimes you need to remove/ move more than one item in Sitecore, and this as you know takes too much time if count of items is too large, The best way to do this is  Sitecore Rocks How to do it? Step1: Install Sitecore rocks Extension into Visual Studio from this link   or you can install it from Visual Studio it self through Extensions and updates in tool bar Step2: Connect your local project with Sitecore Rocks, if you don't know how to connect, please refer to this article Step 3: Below pictures details how easy to delete / move items  This is how you can delete multi items in one shot This is how you can move multi items in one shot  

Sitecore Multi list Code Data Source

Image
Recently, in my project, I had a requirement where, I had to show Items in a list dynamically based on its parent, and we are currently using Multi list with search, and I found it's better to use a custom data source as the query and fast query doesn't work for my case, so, I used the "code" Data source as it's the best solution for my case Below is an example of how I implemented this approach: Case: My case was to map the department with it's company, so I put the path of the company on the parent of the department Code: firstly, you have to add reference for  Sitecore.Bucket.dll as we will implement IDatasource interface public class DepartmentCustomDataSource : IDataSource { public Item[] ListQuery(Item item) { // department company Item parent = item.Parent...