Skip to main content

Posts

Showing posts with the label C#

Featured post

XM Cloud content sync from prod to uat or UAT to prod step by step

When working with Sitecore, it’s common to need content synchronization across environments. Today, I’ll walk you through the steps to sync content from Production to UAT/TEST and vice versa. Steps to Follow 1. Set Up Your Workspace Create a folder on your computer where you will manage the script files and exported data. Open the folder path in PowerShell to begin scripting. We need to run some scripts in PowerShell to update the folder with the basic requirements for syncing content. PS C:\Soft\ContentSync> dotnet new tool-manifest PS C:\Soft\ContentSync> dotnet nuget add source -n Sitecore https://nuget.sitecore.com/resources/v3/index.json PS C:\Soft\ContentSync> dotnet tool install Sitecore.CLI PS C:\Soft\ContentSync> dotnet sitecore cloud login If the above error occurs, you will need to run a different command to resolve the issue. PS C:\Soft\ContentSync> dotnet sitecore init now, Again run above command to open and authenticate with XM Cloud. It will be there a...

How to use async-await method in c#

Here You should just return the result while inside the scope and  the async-await mechanism will make sure   Dispose is called after the operation completes asynchronously .   private async Task < List < String >> GetEntiteesAsync () { using ( var entities = new REPORTEntities ()) { return await ( from user in entities . USERs group user by user . entite into g select g . Key ). ToListAsync (); } }  

How to use extension method in C#

See the below example of extension method. Here , I have created static method in static class . Name "PrintHello" will be call from anther method by declaration of any string variable. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { public static class StringHelper { public static string PrintHello(this string name) { return "Hello , " + name; } } } Here, I have call static method from above to below given code. I have created string name as "name" and directly called the above created static method "PrintHello" that will return the output as "Hello Surendra". --------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { public class Program ...

How to use ternary operator ?

The conditional operator return single value from two value according to condition which is applied. Example of Ternary operator is. You may also check :   Insert,delete,update,select using angularjs with mvc condition ? first_expression : second_expression; int five=5; string answer=((five==5)?(“true”):(“false”); using System; class Program { static void Main() { Console.WriteLine(GetValue("Sam")); Console.WriteLine(GetValue("Jane")); } static int GetValue(string name) { return name == "Sam" ? 100 : -1; } } Output 100 -1

Multilevel Inheritance in C#

Example of Multilevel Inheritance in C# using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test {     class Program     {         static void Main( string [] args)         {             b bb = new c ();            Console .ReadKey();         }     }     class a     {         public   a()         {             Console .WriteLine( "I am a" );         }     }     class b : a     {  ...

How to use connection string in asp.net

Here, You may learn to create connection string in asp.net . Write this code into your code behind file. SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()); Write thi code into your web config file. <appSettings>     <add key="ConnectionString" value="data source=shashi-pc; initial catalog=db_institute_newchanges;uid=sa;pwd=12345;" /> </appSettings>   

How to return data in array by using web method in c#

Here, I have created web method and used with ajax to get value .Here you can learn how to retun data in array and also created list of details class.     [WebMethod]     public static Details[] BindClass()     {         List<Details> Details = new List<Details>();         DataTable dt = new DataTable();         string Query = "select deptid, deptName from dept_master where Status=1";         using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()))         {             using (SqlCommand cmd = new SqlCommand(Query, con))             {                 con.Open();                 SqlDataAdapter da = new SqlDataAdapter(cmd);     ...

How to create properties and use it with Generic class

Here, I have created properties in GetDetails class and use to get large amount of data which comes from database . see below code i have added lots of data in dataset make loop to add all data in list by help of properties . This is best to have good programmer. Follow this type of technique to get data. List<Details > Details = new List<Details >();          if (Ds.Tables[0].Rows.Count > 0)         {             foreach (DataRow dtrow in Ds.Tables[0].Rows)             {                 Details user = new GetDetails();                 user.RowNumber = dtrow["RowNumber"].ToString();                 user.Date = dtrow["Date"].ToString();                 user.FromTime = dtrow["FromTim...

How to use ajax and web method in asp.net

Here , I have created ajax method to call web service and after returning of data from web method i have bind that data into table for more details. please see  below code. $( '#submit ).click( function () {                                $.ajax({                     type: "POST" ,                     contentType: "application/json; charset=utf-8" ,                     url: "details.aspx/Struct" ,                     data: "{}" ,   ...

How to send mail in c# asp.net

Here, I have created method to send mail. Just call this method by passing suitable value in method . It will deliver at you send mail id. apply your email id and password to send mail.      public static string SendMail( string from= "" , string to= "" , string cc= "" , string bcc= "" , string subject= "" , string body= "" , string pass= "" , string host= "" )     {         string strret = "" ;         try         {             string username = from.ToString();             System.Net.Mail. MailMessage MyMailMessage = new System.Net.Mail. MailMessage ();             MyMailMessage.Subject = subject;          ...

How to bind data in grid using web method in asp.net

Here I have created method BindDataGrid () In this method I have used ajax method to get value from database by using web method . Web method return all the required data and bind it in table to form a grid for more details read the below code care fully. This is the web method which call through ajax. [ WebMethod]     public static ScheduleDetails[] BindGridByJs( string Status, string FromDate, string ToDate, string pagesize, string pageno, string Classname, string SubjectName, string TopicName)     {         DataSet Ds = new DataSet();         List<GetLectureScheduleDetails> Details = new List<GetLectureScheduleDetails>();         DataUtility Objdut = new DataUtility();         SqlParameter[] Param = new SqlParameter[10];         Param[0]...