Must-Know Visual Studio Keyboard Shortcuts

Here, I will give you a short list of keyboard short-cuts for things you probably do often in Visual Studio.

Visual Studio Keyboard Shortcuts

Project Related Keyboard Shortcuts

  • Ctrl + Shift + B = Build your project
  • Ctrl + Alt + L = Shows Solution Explorer
  • Shift + Alt + C = Add new class
  • Shift + Alt + A = Add new item to project

Editor Related Keyboard Shortcuts

  • Ctrl + Enter = Insert blank line above the current line
  • Ctrl + Shift + Enter = Insert blank line below the current line
  • Ctrl + Space = Autocomplete using IntelliSense
  • Alt + Shift + arrow keys(←,↑,↓,→) = Select custom part of the code
  • Ctrl + } = Match curly braces, brackets
  • Ctrl + Shift + } = Select text between matched braces, brackets
  • Ctrl + Shift + S = Saves all files and projects
  • Ctrl + K, Ctrl + C = Comments the selected lines
  • Ctrl + K, Ctrl + U = Uncomments the selected lines
  • Ctrl + K, Ctrl + D = Do proper alignment of all the code
  • Shift + End = Select the entire line from start to end
  • Shift + Home = Select the entire line from end to start
  • Ctrl + Delete = Deletes the word to the right of the cursor

Navigation Related Keyboard Shortcuts

  • Ctrl + Up/Down = Scrolls the window without moving the cursor
  • Ctrl + – = Take cursor to its previous location
  • Ctrl + + = Take cursor to its next location
  • F12 = Go to definition

Debugging Related Keyboard Shortcuts

  • Ctrl + Alt + P = Attach to process
  • F10 = Debug step over
  • F5 = Start debugging
  • Shift + F5 = Stop debugging
  • Ctrl + Alt + Q = Add quick watch
  • F9 = Set or remove a breakpoint

Search Related Keyboard Shortcuts

  • Ctrl + K Ctrl + K = Bookmark the current line
  • Ctrl + K Ctrl + N = Navigates to next bookmark
  • Ctrl + . = If you type in a class name like Collection<string> and do not have the proper namespace import, then this shortcut combination will automatically insert the import
  • Ctrl + Shift + F = Find in Files
  • Shift + F12 = Find all references
  • Ctrl + F = Displays the Find Dialog
  • Ctrl + H = Displays the Replace Dialog
  • Ctrl + G = Jumps to the line number or go to the line
  • Ctrl + Shift + F = Find the references of the selected item in the entire solution

Asp.net Difference between Website and Web Application

Generally whenever we are trying to create new web project in visual studio we will found two options ASP.NET Web Application and Web Site. What is the difference between these two which one we need to select to create project in asp.net?

It’s choice of the people can go for web application or website we cannot say that which one is better because both is having advantages and disadvantages. Check below details for web aplication and website.

Web Application

  • If we create any class files / functions those will be placed anywhere in the applications folder structure and it is precomplied into one single DLL.
  • In web application we have chance of select only one programming language during creation of project either C# or VB.NET.
  • Whenever we create Web Application those will automatically create project files (.csproj or .vbproj).
  • We need to pre-compile the site before deployment.
  • If we want to deploy web application project we need to deploy only .aspx pages there is no need to deploy code behind files because the pre-compiled dll will contains these details.
  • If we make small change in one page we need to re-compile the entire sites.
  • By default explicit namespaces are not added to pages, controls or classes, but you can add them manually.

WebSite

  • If we create any class files/functions those will be placed in ASP.NET folder (App_Code folder) and it’s compiled into several DLLs (assemblies) at runtime.
  • In website we can create pages in multi programming languages that means we can create one page code in C# and another page code in vb.net.
  • Web Sites won’t create any .csproj/.vbproj files in project
  • No need to recompile the site before deployment.
  • We need to deploy both .aspx file and code behind file.
  • If we make any code changes those files only will upload there is no need to re-compile entire site
  • By default explicit namespaces are added to pages, controls and classes

when you want to create an Informational project, then go for Website and when you want to create an Interactive project that requires programmatic user input or data processing, and then go for Web Application.

Display Image Preview Without Saving File to Folder – ASP.Net

Hiii, It is easy to upload and save an image to folder and display the uploaded file in Image Control in ASP.Net. But what to do when we want to display an image preview to Image Control of ASP.Net without/before saving to folder ???

So here is the solution for this problem…Check this….

Design Code :

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick = "Upload" />
<hr />
<asp:Panel ID = "Panel1" runat = "server" Visible = "false" >
    <asp:Image ID="Image1" runat="server"/>
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick = "Save" />
</asp:Panel>

Load Event Code :

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Session["Image"] = null;
    }
}

 

Upload Button Event Code :

protected void Upload(object sender, EventArgs e)
{
    Session["Image"] = FileUpload1.PostedFile;
    Stream fs = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(fs);
    byte[] bytes = br.ReadBytes((Int32)fs.Length);
    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
    Image1.ImageUrl = "data:image/png;base64," + base64String;
    Panel1.Visible = true;
}

Save Button Event Code :

protected void Save(object sender, EventArgs e)
{
    HttpPostedFile postedFile = (HttpPostedFile)Session["Image"];
    postedFile.SaveAs(Server.MapPath("~/Uploads/") + Path.GetFileName(postedFile.FileName));
    Response.Redirect(Request.Url.AbsoluteUri);
}

Leave your reply if this post helps you… Thank You.  🙂

Could not load file or assembly ‘CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’ or one of its dependencies

In this post I will explain how to solve problem of “Could not load file or assembly “CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken= 692fbea5521e1304′ or one of its dependencies. The system cannot find the file specified.” during deploy crystal reports in servers.

Generally we will get this problem because of missing crystal report runtime component in server. To solve this problem we need to install CRRedist2008_x86.msi(32 bit) or CRRedist2008_x64.msi(64 bit) based on configuration of client server. We can get it from our development machine location for that path will be here

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5

OR

we can get it from here

Crystal Reports Basic for Visual Studio 2008 x86(32 bit)

Crystal Reports Basic for Visual Studio 2008 x64(64 bit)

After install run time component reset your IIS or restart your server and try your application it will work for you.

jQuery Display Progress Bar on Button Click in Asp.net

Default.aspx

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>jQuery show progress bar on button click asp.net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<style type="text/css">
.sample
{
background-color:#DC5807;
border:1px solid black;
border-collapse:collapse;
color:White;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="DisableDiv"> </div>
<input type="button" id="btnClick" value="Get Data" />
<div id="testdiv"></div>
</form>
<script type="text/javascript">
$(function() {
$('#btnClick').click(function() {
$('#DisableDiv').fadeTo('slow', .6);
$('#DisableDiv').append('<div style="background-color:#E6E6E6;position: absolute;top:0;left:0;width: 100%;height:300%;z-index:1001;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);"><img src="loading.gif" style="background-color:Aqua;position:fixed; top:40%; left:46%;"/></div>');
setTimeout(function() { GetData() }, 1000)
})
});
function GetData()
{
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ShowLoadingImageonButtonClick.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function(data) {
var theHtml = data.d;
$('#testdiv').html(theHtml)
$('#DisableDiv').html("");
},
error: function(result) {
alert("Error");
}
});
}
</script>
</body>
</html>

Default.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string BindDatatable()
{
GridView gv = new GridView();
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true"))
{
using (SqlCommand cmd = new SqlCommand("select UserId,UserName,Location from UserInformation", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
}
gv.HeaderStyle.CssClass = "sample";
gv.DataSource = dt;
gv.DataBind();
gv.RenderControl(htmlWriter);
return stringWriter.ToString();
}

 

jQuery Higlight Table Row & Column on Mouseover in Asp.net

Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>Asp.net Bind Data to Datatable using JQuery or JSON</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function(data) {
for (var i = 0; i < data.d.length; i++) {
if (i % 2 == 0) {
$("#tbDetails").append("<tr class=tg-even><td>" + data.d[i].Tagid + "</td><td>" + data.d[i].TagName + "</td><td>" + data.d[i].Noofarticles + "</td></tr>");
}
else {
$("#tbDetails").append("<tr><td>" + data.d[i].Tagid + "</td><td>" + data.d[i].TagName + "</td><td>" + data.d[i].Noofarticles + "</td></tr>");
}
}
$('td').mouseover(function() {
$(this).siblings().css('background-color', '#EAD575');
var ind = $(this).index();
$('td:nth-child(' + (ind + 1) + ')').css('background-color', '#EAD575');
});
$('td').mouseleave(function() {
$(this).siblings().css('background-color', '');
var ind = $(this).index();
$('td:nth-child(' + (ind + 1) + ')').css('background-color', '');
});
},
error: function(result) {
alert("Error");
}
});
});
</script>
<style type='text/css'>
.tbl {
border-collapse: collapse;
border-spacing: 0;
}
.tbl td, .tbl th {
background-color: #fff;
border: 1px #bbb solid;
color: #333;
font-family: sans-serif;
font-size: 100%;
padding: 10px;
vertical-align: top;
}
.tbl .tg-even td {
background-color: #eee;
}
.tbl th {
background-color: #ddd;
color: #333;
font-size: 110%;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table id="tbDetails" class="tbl">
<tr >
<th>UserId</th>
<th>UserName</th>
<th>Location</th>
</tr>
<tbody>
</tbody>
</table>
</form>
</body>
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Services;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static UserDetails[] BindDatatable()
{
List<UserDetails> details = new List<UserDetails>();
DataTable dt = new DataTable();
dt.Columns.Add("Tagid", typeof(Int32));
dt.Columns.Add("TagName", typeof(string));
dt.Columns.Add("Noofarticles", typeof(string));
dt.Rows.Add(1, "Asp.Net", 100);
dt.Rows.Add(2, "C#.Net", 10);
dt.Rows.Add(3, "SQL Server", 30);
dt.Rows.Add(4, "jQuery", 20);
dt.Rows.Add(6, "javascript", 15);
dt.Rows.Add(7, "XSLT", 50);
foreach (DataRow dtrow in dt.Rows)
{
UserDetails user = new UserDetails();
user.Tagid = dtrow["Tagid"].ToString();
user.TagName = dtrow["TagName"].ToString();
user.Noofarticles = dtrow["Noofarticles"].ToString();
details.Add(user);
}
return details.ToArray();
}
public class UserDetails
{
public string Tagid { get; set; }
public string TagName { get; set; }
public string Noofarticles { get; set; }
}
}

 

 

how to Import data from EXCEL to SQL Database in ASP.NET

Here I will explain how to Import or insert data into SQL database from Excel spreadsheet using Sqlbulkcopy method.

I have searched for so many posts that explain static manner some of the posts are not clearly some of the posts are not supporting for latest excel files so many problems i faced by using those examples I have done application that will support for all excel versions and it will work for you without having any problems and it will dynamically you can upload excel sheet from anywhere from your computer.

I want to copy this data into a SQL Server Database Table, called Excel_table, with the same schema. Design your tables in database like this

Databasefile
aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<span style="color: Red">*</span>Attach Excel file
</td>
<td>
<asp:FileUpload ID="fileuploadExcel" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click"  />
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>

code in codebehind button click

protected void btnSend_Click(object sender, EventArgs e)
{
 String strConnection = "Data Source=MySystem;Initial Catalog=MySamplesDB;Integrated Security=True";
//file upload path
string path = fileuploadExcel.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection =new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[Designation] from [Sheet1$]",excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "Excel_table";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
}