Posts

Showing posts from January, 2021

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...