Posts

Write a C# program to print the noofcharacters , noof words,noof lines from a text file?

Q2. And also write a program to read the file from current directory and do the same operation  //namespaces  using System.IO; using System; class Program {     static void Main()     {         Console.WriteLine("Hello, World!");        //below code line is used to get all filenames from the current directory         string[] _fileNamesInDirectory = Directory.GetFiles(Directory.GetCurrentDirectory());        foreach(var item in _fileNamesInDirectory)         {        //below code is used to get the filepath for each file using directory and filename         string filepath = Path.Combine(Directory.GetCurrentDirectory(), item);          if(!string.IsNullOrEmpty(filepath))           {         //here we are getting the file extension ...

Interview Questions 3

Level 4 company : Explain the project structure and each significance? Write a program to identify whether a given string is palindrome or not using recursion? Program to print the repeated count of characters string str=“hello”; char c; for(int i=0;i<str.length();i++){ int count=0; c=str[i]; for(int j=1;j<str.length();j++){ if(c==str[j]){ count=count+1; } } console.write(c+“has repeated ”+count+”times”); count=0; } and write the above program using linq?

Interview Questions-2

 output of following program and if any errors what should be the correct syntax class baseclass {​​​​​​​​​      public void func1() {​​​​​​​​ Console.WriteLine ("Base Fun1()")​}​​​​​​​​​      public virtual void func2() {​​​​​​​​ Console.WriteLine ("Base Fun2()")​}​​​​​​​​​      public virtual  void func3() {​​​​​​​​​ Console.WriteLine ("Base Fun3()")}​​​​​​​​​ }​​​​​​​​​ class derivedclass :baseclass {​​​​​​​​​      new public void func1() {​​​​​​​​ Console.WriteLine ("derived Fun1()")​}​​​​​​​​​      public override void func2() {​​​​​​​​ Console.WriteLine ("derived Fun2()")​}​​​​​​​​​      public new void func3() {​​​​​​​​ Console.WriteLine ("derived Fun3()")​}​​​​​​​​​ }​​​​​​​​​ class Program {​​​​​​​​​      static void Main(string[] args)      {​...

Top MNC Interview Questions- Full Stack Developer

Common Questions: What is Reflection? What is data integrity In SQL Server? Different types of relationships in SQL Server? Different b/w Union, Union All, Minus, Intersect? When we use the method overloading concept in c#? Real-time example for oops concepts? Why we go for Interfaces when we have abstract Classes? (Note: Provide Reason other than multiple inheritances, and abstraction concept). What is the Bundling and Minification Concept? What are the different options available in google chrome developer tools? Can we call the same request again from the network tab in the google chrome developer tab? What are ACID properties in SQL Server? What is CTE? Where we can use it and why? What are the components of ado.net? Types of Cookies in MVC and how the memory allocated? Diff. b/w array.clone() and array.copyto()? Why we need relations in SQL? Diff. b/w Task and Thread? How do you implement dependency injection in MVC .net standard f/w? Async and Await? Task and Task<T>? Diffe...

How to update the user level when ever user report any tweet in sql

  ALTER PROCEDURE [dbo].[SP_UPDATEUSERLEVEL] @Userid INT AS BEGIN Declare @CountOfUserReportedTweets INT Declare @LevelBadgeId INT SET @CountOfUserReportedTweets=(select count(*) from OnGoingReports where UserId=@Userid) --CHECKS WHETHER THE LEVEL EXIST OR NOT IF EXISTS(select Top 1 * from LevelBadge where NoofTweets<=@CountOfUserReportedTweets order by NoofTweets desc) BEGIN --IF LEVEL EXISTS UPDATE OR INSERT WITH THAT LEVEL ID SET @LevelBadgeId=(select Top 1 Id from LevelBadge where NoofTweets<=@CountOfUserReportedTweets order by NoofTweets desc) IF EXISTS(select * from UserLevel where UserId=@Userid) BEGIN UPDATE UserLevel SET LevelBadgeId=@LevelBadgeId WHERE UserId=@Userid END ELSE BEGIN INSERT INTO UserLevel(UserId,LevelBadgeId) VALUES (@Userid,@LevelBadgeId) END END ELSE BEGIN --IF NO LEVEL EXISTS THEN INSERTING DEFAULT LEVEL IF EXISTS(select * from UserLevel where UserId=@Userid) BEGIN UPDATE UserLeve...

How to get the user details, user current level, next level, Rank in sql server

 ALTER PROCEDURE [dbo].[SP_GETUSERPROFILE] @UserId int AS BEGIN --checks whether user reported any tweet or not IF EXISTS(SELECT * FROM OnGoingReports WHERE UserId=@UserId) BEGIN --if user already reported tweets then gets the user details and rank select UserId,UserName,Name,UserReportedTweetCount,Rank      from  (select UserId,UserName,Name,UserReportedTweetCount,ROW_NUMBER() OVER(ORDER BY UserReportedTweetCount desc) AS Rank  from      (select ogr.UserId,uc.UserName,Name,Count(*) UserReportedTweetCount from UserCredentials uc       inner join OnGoingReports ogr       on       ogr.UserId=uc.UserId        GROUP BY ogr.UserId,uc.Name,uc.UserName) as TopList ) as UserRank      where UserId=@UserId END ELSE BEGIN --if user not reported any tweets then it get the default value as 0 and rank based on tweets reported select UserId,UserName,Nam...

How to get tweets under topic and also the status whether the logged in user reported the tweet or not in sql server

 ALTER PROCEDURE [dbo].[SP_GETTWEETSBYTOPIC_REPORTEDSTATUS] @TopicId INT, @UserId INT AS BEGIN select distinct tw.TweetId,tw.Id,tw.CreatedOn, tw.TwitterHandle,tw.TwitterProfileLink,tw.Tweet,tw.TweetedOn,tw.Rating, tw.NoofComments,tw.NoofLikes,tw.NoofReTweets,tw.IsActive, (select case when ogr.userid IS NOT NULL and ogr.TweetId IS NOT NULL then CAST(1 AS BIT) else CAST(0 AS BIT) end as isreported ) IsReported from tweets tw inner join tweettopic tt on tt.twtid=tw.id left join ongoingreports ogr on ogr.TweetId=tw.TweetId and ogr.UserId=@UserId where tt.TopicId=@TopicId and tw.IsActive=1 and  (UPPER(tw.Rating)='NEGATIVE' OR UPPER(tw.Rating)='FALSE') END

How to get the top 10 members based nooftweets reported and also the logged in user rank

  CREATE PROCEDURE [dbo].[SP_GETLEADERBOARD]  @UserId INT  AS  BEGIN   DECLARE @IsExist Int IF EXISTS(Select * from OnGoingReports where UserId=@UserId) BEGIN SET @IsExist=1 END ELSE BEGIN SET @IsExist=0 END --gets the user name,tweetsreported,rank of top 10 users from ongoingreports table select Top 10 UserId,Name,UserReportedTweetCount,ROW_NUMBER() OVER(ORDER BY UserReportedTweetCount desc) AS Rank  from (select ogr.UserId,Name,Count(*) UserReportedTweetCount from UserCredentials uc inner join OnGoingReports ogr on ogr.UserId=uc.UserId  where uc.IsActive=1 GROUP BY ogr.UserId,uc.Name) TopList   UNION    --if user reported then the if block executes and calculates rank based on tweets reported select UserId,Name,UserReportedTweetCount,Rank from (select UserId,Name,UserReportedTweetCount,ROW_NUMBER() OVER(ORDER BY UserReportedTweetCount desc) AS Ran...

How to Read list of objects from json file and convert it into list of objects in c# .net core

  public List<CityMaster> getcities()         {             List<CityMaster> cities = new List<CityMaster>();             try             {                 var res = new List<CityMaster>();                 string path1 = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\assets\citieslist.json"}";                 using (StreamReader r = new StreamReader(path1))                 {                     string json = r.ReadToEnd();                     res = JsonConvert.DeserializeObject<List<CityMaster>>(json);                 }      ...

How to get the count of orgs under each city in Sql Server

 SELECT City, COUNT (OrgId) as NoofOrgs FROM Organisation_Address oa inner join Organisations org  on org.Id=oa.OrgId Where City!='' and Org.IsActive=1 and org.IsApproved=1 GROUP BY City 

How to get the parent child relation in same table In Sql Server

SELECT ChildUserType.Id as CategoryId,ChildUserType.Category as CategoryName, ChildUserType.IsActive,ChildUserType.CategoryURL as CategoryURL, ChildUserType.CreatedOn,ChildUserType.ParentId, ParentUserType.Category as ChildParentname,ChildUserType.NoofOrgs FROM  [dbo].[Categories] AS ChildUserType LEFT JOIN  [dbo].[Categories] AS ParentUserType  ON  ChildUserType.ParentId = ParentUserType.Id 

How to Create trigger to Update the NoofOrgs Count under each category in Category Table based on Temp Table in Sql Server

--creating a trigger CREATE TRIGGER [dbo].UPDATEORGSCOUNTINCATEGORY_AFTERINSERT_FROMORGANISATIONS]   ON --here we mention the table name   [dbo].[Organisations] --here we can have insert, update, delete as trigger point --I want to execute my trigger when a record is inserted in organizations table (step-1) --then get the count of orgs in each category from organisationcategories table and save it in temp table(step-2) --then update the category table with orgs count in each category(step-3)   AFTER INSERT   AS   BEGIN   --we are updating the count bcz a listing or nonprofi can be approved or rejected then the count changes. --creating a temp table with two columns of int type DECLARE @temp TABLE ( CategoryId INT, NoofOrgs INT ) --inserting values into temp table INSERT INTO @temp SELECT * from (         --here we are selecting these two columns select CategoryId,ISNULL(NoofOrgs , 0) AS 'NoofOrgs' from (   ...

How to Get Datetime Wrt Time Zone in C#

  public static DateTime GetDateTime()   { //here we are trying to get the indian datetime irrespective of hosted server location             TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");             DateTime now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);             return now;   }

How to Read Countries, States, Cities data from Json file and Convert to List Objects in C#.

 Here I'm attaching the Json String of Countries List, States List, Cities List and also the scripts for all countries, states, cities. You can just , use and convert the Json string to List Object and use them. Models For Country, State, City: public class CountryMaster { public int ID { get; set; } public string CountryName { get; set; } public string CountryCode { get; set; } } public class StateMaster { public int ID { get; set; } public string StateName { get; set; } public int CountryID { get; set; } } public class CityMaster { public int ID { get; set; } public string CityName { get; set; } public int StateID { get; set; } } Note: The above models are as per json   For Sample, To get the country list you can use below code,  var res = JsonConvert.DeserializeObject<List<CountryMaster>>("country json string");  Drive link: drivelink     

How to Show only certain characters and bind '...' at end in mvc view in c#

  <span class="text-muted"> //here we show upto 200 characters and then '...' are shown @(item.Content.Length > 200 ? item.Content.Substring(0, 200) + "..." : item.Content) </span> 

How to Remove html tags from string in c#

  private List<ArticlesEntity> RemoveHtmltags(List<ArticlesEntity> articles)         {             List<ArticlesEntity> artls = new List<ArticlesEntity>();             artls = articles;             foreach(var item in artls)             {                 if (item.Content != "" && item.Content != null && item.Content != string.Empty)                 {                     item.Content= Regex.Replace(item.Content, "<.*?>", " ");//here html tags are removed                 }             }             return artls;         }

How to Preview the image and download which is in base64string format in mvc view using C#

  <div class="col-lg-9 col-xl-6">                                                     @if (reclaimdetai != null)                                                     {                                                         @foreach (var item in reclaimdetai.RequestFileList)                                                         {                                 ...

How to Change Layout based on viewbag value in mvc view using Mvc,C#

 @{     if (@ViewBag.lang == "en")     {         Layout = "Layout Name 1"; //This content uses above layout     }     if (@ViewBag.lang == "ar")     {         Layout = "Layout Name 2"; //This content uses above layout     } }

How to Get the current url and redirect to other url(case:button click english to arabic screen using parameter in url) using jquery,mvc,c#

   <a class="btn btn-icon btn-clean btn-lg w-40px h-40px btnlang" id="btnlang" > Change Lang </a> sample url:  https://localhost:44310/Claims/AddClaim?lang=en <script src="~/lib/jquery/dist/jquery.min.js"></script> <script>     $(document).ready(function () {         $('.btnlang').click(function () {             debugger;             var pageURL = $(location).attr("href");//gets the current url             var baseaddress = pageURL.substring(0, pageURL.indexOf('?'));//get the base address before '?'             var tech = getUrlParameter('lang');//gets the parameter using parameter name i.e,lang             if (tech == "en") {                 location.href = baseaddress + "?lang=ar";             }...

How to write Function to validate input password pattern in mvc using Jquery

 function validatepin(cpin) {     //var paswd = /^(?=.*\d)(?=.*[^a-zA-Z0-9])(?!.*\s).{8,8}$/;     if (containsCharacters(cpin) && containsNumber(cpin) && containsSpecialCharacters(cpin)) {                return true;     } else {                return false;     } } function containsCharacters(val) { var regex = /[A-z]/; var isValid = regex.test(val); return isValid; } function containsNumber(val) { var regex = /[0-9]/; var isValid = regex.test(val); return isValid; } function containsSpecialCharacters(val) { var regex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/; var isValid = regex.test(val); return isValid; }