| S.No | Particulars | ASP.NET WebAPI | ASP.NET MVC |
|---|---|---|---|
| 1 | Create Web App | create full blown HTTP services with easy and simple way that returns only data not view. | returns both views and data |
| 2 | support content-negotiation | Yes | No |
| 3 | returning data | JSON,XML or any other based upon the Accept header in the request and you don't worry about that. | JSON format using JsonResult. |
| 4 | request are mapped | actions based on HTTP verbs | mapped to actions name. |
| 5 | assembly | System.Web.Http | System.Web.Mvc |
| 6 | mixed MVC and Web API controller | Web API since boths are different. | implement the authorization then you have to create two filters one for MVC |
ASP.Net Web API vs ASP.NET MVC
Labels:
ASP.Net
Split Web Page Extention using C#.Net
Split Web Page Extention using C#.Net
using System.Text.RegularExpressions;
string splitWebPageExtension(string webPage, string extension,int idx)
{
Regex Splitter = new Regex(extension);
String[] Parts = Splitter.Split(webPage);
string st = Parts[idx];
return st;
}
string webPage = "http://dotnettechrocks.blogspot.in/ ";
string str = splitWebPageExtension(webPage, ".in", 0);
MessageBox.Show(str);
Result :http://dotnettechrocks.blogspot
using System.Text.RegularExpressions;
string splitWebPageExtension(string webPage, string extension,int idx)
{
Regex Splitter = new Regex(extension);
String[] Parts = Splitter.Split(webPage);
string st = Parts[idx];
return st;
}
string webPage = "http://dotnettechrocks.blogspot.in/ ";
string str = splitWebPageExtension(webPage, ".in", 0);
MessageBox.Show(str);
Result :http://dotnettechrocks.blogspot
Labels:
ASP.Net
Cluster vs NON-Cluster Index
| S.No | Particulars | Cluster | NON-Cluster |
|---|---|---|---|
| 1 | data rows | sort and store the data rows in the table or view based on their key values. | have a structure separate from the data rows. |
| 2 | Read | Faster to read than NON-Cluster | |
| 3 | Store | Physically, Store Index Order | |
| 4 | Faster Insert/Update | Qucikly Insert and Update Data than a Cluster Index. | |
| 5 | Table | Only One Per Table | can be used many time per Table |
| 6 | Order | Data is in Physical Order | Logical Order |
Labels:
Interview Question and Answer
Function vs Methods
| S.No | Particulars | Funciton | Methods |
|---|---|---|---|
| 1 | independent existence | they can be defined outside of the class | they are always defined with in class |
| 2 | languages | Structure languages | object oriented languages |
| 3 | independently | called independently. | called using instance or object. |
| 4 | Functions are self describing unit of code. | Methods are used to manipuate instance variable of a class |
Labels:
OOPS
Web Services vs WCF
| S.No | Particulars | Web services | WCF |
|---|---|---|---|
| 1 | Support SOAP | Yes | Yes |
| 2 | Support | HTTP | TCP, HTTP, HTTPS, Named Pipes, MSMQ. |
| 3 | Return Data | XML | XML |
| 4 | Open Source | No, can be consumed by any client that understands xml. | No, can be consumed by any client that understands xml. |
| 5 | Host | only IIS | IIS or Windows Services |
Labels:
ASP.Net
Create Directory Date Format in C#.Net
This is a Code for "Create Directory Date Format in C#.net"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GetOfficeVersion
{
class ClsDirectory
{
public static void CreateDirectory(string DesignationPath)
{
if (!Directory.Exists(DesignationPath))
{
Directory.CreateDirectory(DesignationPath);
}
}
public static string currentYear()
{
string Year = string.Empty;
DateTime dt = DateTime.Now;
string format = "yyyy";
Year = dt.ToString(format);
return Year;
}
public static string currentMonth()
{
string Month = string.Empty;
DateTime dt = DateTime.Now;
string format = "MM";
Month = dt.ToString(format);
return Month;
}
public static string currentDate()
{
string day = string.Empty;
DateTime dt = DateTime.Now;
string format = "dd";
day = dt.ToString(format); return day;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GetOfficeVersion
{
class ClsDirectory
{
public static void CreateDirectory(string DesignationPath)
{
if (!Directory.Exists(DesignationPath))
{
Directory.CreateDirectory(DesignationPath);
}
}
public static string currentYear()
{
string Year = string.Empty;
DateTime dt = DateTime.Now;
string format = "yyyy";
Year = dt.ToString(format);
return Year;
}
public static string currentMonth()
{
string Month = string.Empty;
DateTime dt = DateTime.Now;
string format = "MM";
Month = dt.ToString(format);
return Month;
}
public static string currentDate()
{
string day = string.Empty;
DateTime dt = DateTime.Now;
string format = "dd";
day = dt.ToString(format); return day;
}
}
}
Labels:
C#.Net
Model View Controller
Today, we see What is mean by MVC [Model View Control]
Model:
- Model is basically a C# or VB.Net Class.
- Model is accessible by Both Controller and View.
- Model can be used to pass data from Controller to View.
- View can use model to display data in Page.
- View is an ASPX Page without having a Code Behide file.
- All Pate specific HTML generation and formatting can be done inside view.
- One can use inline Code(Server tags) to develop dynamic pages.
- Controller is a basically a C# or VB.net class which inherits System.MVC.Controller.
- controller is a Heart of Entire MVC Architecture.
- Inside Controller's Class action methods can be implemented which are responsible to responding to browser or calling views.
- Controller can access and use model class to pass data to views
- Controller uses ViewData to pass any data to view.
Labels:
MVC
Mandatory Label
Introduction:
Today , we discussed about Mandatory Label in C#.Net. This label intimate to user ,It is a Mandatory Field.
Today , we discussed about Mandatory Label in C#.Net. This label intimate to user ,It is a Mandatory Field.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace StaffingSolutionV1.UtilityLayer
{
class MandatoryLable :Label
{
public enum StatusManLabel
{
False,
True
};
private StatusManLabel m_Status;
public string AddSymbol
{
get;
set;
}
public StatusManLabel StatusLabel
{
get
{
return m_Status;
}
set
{
if (value == StatusManLabel.True)
{
this.Text = AddSymbol + " " + this.Text; }
else
{
AddSymbol = ""; this.Text = "";
}
m_Status = value;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace StaffingSolutionV1.UtilityLayer
{
class MandatoryLable :Label
{
public enum StatusManLabel
{
False,
True
};
private StatusManLabel m_Status;
public string AddSymbol
{
get;
set;
}
public StatusManLabel StatusLabel
{
get
{
return m_Status;
}
set
{
if (value == StatusManLabel.True)
{
this.Text = AddSymbol + " " + this.Text; }
else
{
AddSymbol = ""; this.Text = "";
}
m_Status = value;
}
}
}
}
Labels:
User Control
Number TextBox
Hi All,
Today ,we see how to Create Number TextBox?
Today ,we see how to Create Number TextBox?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace LaksUserControl.UtilityLayer
{
class NumberTextBox : TextBox
{
CustomErrorProvider objCEP = new CustomErrorProvider();
public enum CheckStatus { True, False, };
public enum CheckStatusBlank { True, False, };
enum ValidatieonType { BLANK, CHARACTER, BLANKWITHCHARACTER, };
private CheckStatus m_CheckStatus;
private CheckStatusBlank m_CheckStatusBlank;
public CheckStatus CheckErrorProvider
{
get
{
return m_CheckStatus;
}
set
{
m_CheckStatus = value;
}
}
public CheckStatusBlank CheckEmptyBox
{
get
{
return m_CheckStatusBlank;
}
set
{
m_CheckStatusBlank = value;
}
}
private bool CheckBlankTextBox()
{
if (string.IsNullOrEmpty(this.Text))
return true;
else
return false;
}
private bool ValidateNumber(string str)
{
Regex regexAlphaNum = new Regex(@"^[0-9]*$");
return regexAlphaNum.IsMatch(str);
}
bool checkBlank;
private bool CheckBlankTextBox(ValidatieonType Mode)
{
switch (Mode)
{
case ValidatieonType.BLANK:
if (string.IsNullOrEmpty(this.Text))
checkBlank = true;
else
checkBlank = false;
break;
case ValidatieonType.CHARACTER:
if (!ValidateNumber(this.Text))
checkBlank = true;
else
checkBlank = false;
break;
case ValidatieonType.BLANKWITHCHARACTER:
if (string.IsNullOrEmpty(this.Text) | !ValidateNumber(this.Text))
checkBlank = true;
else checkBlank = false;
break;
}
return checkBlank;
}
bool chkdisplayEP;
protected internal bool DisplayErrorProvider(string CheckErrorProvider, string CheckEmptyBox, string Message)
{
if (CheckErrorProvider == "true" && CheckEmptyBox == "true")
{
if (CheckBlankTextBox(ValidatieonType.BLANKWITHCHARACTER))
{
objCEP.SetError(this, Message);
chkdisplayEP = true;
}
else
{
objCEP.SetError(this, "");
chkdisplayEP = false;
}
}
else if ((CheckErrorProvider == "true" && CheckEmptyBox == "false"))
{
if (CheckBlankTextBox(ValidatieonType.CHARACTER))
{
objCEP.SetError(this, Message);
chkdisplayEP = true;
}
else
{
objCEP.SetError(this, "");
chkdisplayEP = false;
}
}
return chkdisplayEP;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LaksUserControl.UtilityLayer
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace LaksUserControl.UtilityLayer
{
class NumberTextBox : TextBox
{
CustomErrorProvider objCEP = new CustomErrorProvider();
public enum CheckStatus { True, False, };
public enum CheckStatusBlank { True, False, };
enum ValidatieonType { BLANK, CHARACTER, BLANKWITHCHARACTER, };
private CheckStatus m_CheckStatus;
private CheckStatusBlank m_CheckStatusBlank;
public CheckStatus CheckErrorProvider
{
get
{
return m_CheckStatus;
}
set
{
m_CheckStatus = value;
}
}
public CheckStatusBlank CheckEmptyBox
{
get
{
return m_CheckStatusBlank;
}
set
{
m_CheckStatusBlank = value;
}
}
private bool CheckBlankTextBox()
{
if (string.IsNullOrEmpty(this.Text))
return true;
else
return false;
}
private bool ValidateNumber(string str)
{
Regex regexAlphaNum = new Regex(@"^[0-9]*$");
return regexAlphaNum.IsMatch(str);
}
bool checkBlank;
private bool CheckBlankTextBox(ValidatieonType Mode)
{
switch (Mode)
{
case ValidatieonType.BLANK:
if (string.IsNullOrEmpty(this.Text))
checkBlank = true;
else
checkBlank = false;
break;
case ValidatieonType.CHARACTER:
if (!ValidateNumber(this.Text))
checkBlank = true;
else
checkBlank = false;
break;
case ValidatieonType.BLANKWITHCHARACTER:
if (string.IsNullOrEmpty(this.Text) | !ValidateNumber(this.Text))
checkBlank = true;
else checkBlank = false;
break;
}
return checkBlank;
}
bool chkdisplayEP;
protected internal bool DisplayErrorProvider(string CheckErrorProvider, string CheckEmptyBox, string Message)
{
if (CheckErrorProvider == "true" && CheckEmptyBox == "true")
{
if (CheckBlankTextBox(ValidatieonType.BLANKWITHCHARACTER))
{
objCEP.SetError(this, Message);
chkdisplayEP = true;
}
else
{
objCEP.SetError(this, "");
chkdisplayEP = false;
}
}
else if ((CheckErrorProvider == "true" && CheckEmptyBox == "false"))
{
if (CheckBlankTextBox(ValidatieonType.CHARACTER))
{
objCEP.SetError(this, Message);
chkdisplayEP = true;
}
else
{
objCEP.SetError(this, "");
chkdisplayEP = false;
}
}
return chkdisplayEP;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LaksUserControl.UtilityLayer
{
class CustomErrorProvider : ErrorProvider
{
public List GetControls()
{
return this.GetControls(this.ContainerControl);
}
public List GetControls(Control ParentControl)
{
List ret = new List();
if (!string.IsNullOrEmpty(this.GetError(ParentControl)))
ret.Add(ParentControl);
foreach (Control c in ParentControl.Controls)
{
List child = GetControls(c);
if (child.Count > 0)
ret.AddRange(child);
}
return ret;
}
}
}
</div>
{
public List
Labels:
User Control
Get DataBase Exists or not using DataContext
This is code for Get DataBase Exists or not using DataContext
DataContext context = new DataContext(GetConnectionString("YourSErverName"));
bool dbExists = context.DatabaseExists();
if (dbExists)
{
MessageBox.Show("Database Exists");
}
else
{
MessageBox.Show("Database doesn't Exist");
}
static string GetConnectionString(string serverName)
{
System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = serverName; builder["integrated Security"] = true;
builder["Initial Catalog"] = "Sample2"; Console.WriteLine(builder.ConnectionString); Console.ReadKey(true); return builder.ConnectionString;
}
bool dbExists = context.DatabaseExists();
if (dbExists)
{
MessageBox.Show("Database Exists");
}
else
{
MessageBox.Show("Database doesn't Exist");
}
static string GetConnectionString(string serverName)
{
System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = serverName; builder["integrated Security"] = true;
builder["Initial Catalog"] = "Sample2"; Console.WriteLine(builder.ConnectionString); Console.ReadKey(true); return builder.ConnectionString;
}
Labels:
Interview Question and Answer