class Program
{
static void Main(string[] args)
{
int a;
ConsoleKeyInfo keypress = Console.ReadKey();
if (keypress.Key == ConsoleKey.Escape)
{
Console.WriteLine("You are pressed Escape");
}
a = keypress.KeyChar;
if (a == 13)
{
Console.WriteLine("You are pressed Enter");
}
keypress = Console.ReadKey();
if (keypress.Key == ConsoleKey.X &&
keypress.Modifiers == ConsoleModifiers.Control)
{
Console.WriteLine("You are pressed CTRL+X");
}
Console.Read();
}
Monday, 14 May 2012
Functions used with Console Class in C#
Thursday, 10 May 2012
Introduction To Web
The World Wide Web (abbreviated as WWW or W3, commonly known as the Web, or the "Information Superhighway"), is a system of interlinked hypertext documents accessed via the Internet. With a web browser, one can view web pages that may contain text, images, videos, and other multimedia, and navigate between them via hyperlinks.
A website, also written as Web site, web site, or simply site, is a set of related web pages containing content (media) such as text, image, video, audio, etc. A website is hosted on at least one web server, accessible via a network such as the Internet or a private local area network through an Internet address known as a Uniform Resource Locator. All publicly accessible websites collectively constitute the World Wide Web.
A webpage is a document, typically written in plain text interspersed with formatting instructions of Hypertext Markup Language (HTML, XHTML). A webpage may incorporate elements from other websites with suitable markup anchors.
Static website
A static website is one that has web pages stored on the server in the format that is sent to a client web browser. It is primarily coded in Hypertext Markup Language (HTML).
Simple forms or marketing examples of websites, such as classic website, a five-page website or a brochure website are often static websites, because they present pre-defined, static information to the user. This may include information about a company and its products and services through text, photos, animations, audio/video and interactive menus and navigation.
Dynamic website
A dynamic website is one that changes or customizes itself frequently and automatically, based on certain criteria.
Dynamic websites can have two types of dynamic activity: Code and Content. Dynamic code is invisible or behind the scenes and dynamic content is visible or fully displayed.
Dynamic code
The first type is a web page with dynamic code. The code is constructed dynamically on the fly using active programming language instead of plain, static HTML.
A website with dynamic code refers to its construction or how it is built, and more specifically refers to the code used to create a single web page. A dynamic web page is generated on the fly by piecing together certain blocks of code, procedures or routines. A dynamically-generated web page would recall various bits of information from a database and put them together in a pre-defined format to present the reader with a coherent page. It interacts with users in a variety of ways including by reading cookies recognizing users' previous history, session variables, server side variables etc., or by using direct interaction (form elements, mouse overs, etc.). A site can display the current state of a dialogue between users, monitor a changing situation, or provide information in some way personalized to the requirements of the individual user.
Dynamic content
The second type is a website with dynamic content displayed in plain view. Variable content is displayed dynamically on the fly based on certain criteria, usually by retrieving content stored in a database.
A website with dynamic content refers to how its messages, text, images and other information are displayed on the web page, and more specifically how its content changes at any given moment. The web page content varies based on certain criteria, either pre-defined rules or variable user input. For example, a website with a database of news articles can use a pre-defined rule which tells it to display all news articles for today's date. This type of dynamic website will automatically show the most current news articles on any given date. Another example of dynamic content is when a retail website with a database of media products allows a user to input a search request for the keyword Beatles. In response, the content of the web page will spontaneously change the way it looked before, and will then display a list of Beatles products like CDs, DVDs and books.
Webpages are accessed and transported with the Hypertext Transfer Protocol (HTTP), which may optionally employ encryption (HTTP Secure, HTTPS) to provide security and privacy for the user of the webpage content. The user's application, often a web browser, renders the page content according to its HTML markup instructions onto a display terminal.
The pages of a website can usually be accessed from a simple Uniform Resource Locator (URL) called the web address. The URLs of the pages organize them into a hierarchy, although hyperlinking between them conveys the reader's perceived site structure and guides the reader's navigation of the site which generally includes a home page with most of the links to the site's web content, and a supplementary about, contact and link page.
A web application is an application that is accessed over a network such as the Internet or an intranet. The term may also mean a computer software application that is coded in a browser-supported language (such as JavaScript, combined with a browser-rendered markup language like HTML) and reliant on a common web browser to render the application executable.
A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier (URI) and may be a web page, image, video, or other piece of content.Hyperlinks present in resources enable users easily to navigate their browsers to related resources. A web browser can also be defined as an application software or program designed to enable users to access, retrieve and view documents and other resources on the Internet.
Web server can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver Web content that can be accessed through the Internet.The most common use of web servers is to host websites, but there are other uses such as gaming, data storage or running enterprise applications.
A web hosting service is a type of Internet hosting service that allows individuals and organizations to make their website accessible via the World Wide Web.In order to publish a website online, you need a Web host. The Web host stores all the pages of your website and makes them available to computers connected to the Internet. The domain name, such as "sony.com," is actually linked to an IP address that points to a specific computer. When somebody enters your domain name into their browser's address field, the IP address is located and Web site is loaded from your Web host.
The term Web services describes a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available. Used primarily as a means for businesses to communicate with each other and with clients, Web services allow organizations to communicate data without intimate knowledge of each other's IT systems behind the firewall
Wednesday, 2 May 2012
.Net Introduction
The Microsoft .Net Framework is a
platform that provides tools and technologies you need to build Networked
Applications as well as Distributed Web Services and Web Applications. The .Net
Framework provides the necessary compile time and run-time foundation to build
and run any language that conforms to the Common Language Specification
(CLS).The main two components of .Net Framework are Common Language Runtime
(CLR) and .Net Framework Class Library (FCL).
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all platforms supported by Microsoft Windows, Windows Mobile, Windows CE, .NET Framework, .NET Compact Framework and Microsoft Silverlight.
Visual Studio includes a code editor supporting IntelliSense as well as code refactoring. The integrated debugger works both as a source-level debugger and a machine-level debugger. Other built-in tools include a forms designer for building GUI applications, web designer, class designer, and database schema designer.
Microsoft started the development on
the .NET Framework in the late 1990s originally under the name of Next
Generation Windows Services (NGWS). By late 2000 the first beta versions of
.NET 1.0 were released.
Version 3.0 of the .NET Framework is
included with Windows Server 2008 and Windows Vista. Version 3.5 is included
with Windows 7, and can also be installed on Windows XP and the Windows Server
2003 family of operating systems. On 12 April 2010, .NET Framework 4 was
released alongside Visual Studio 2010.
The .NET Framework family also
includes two versions for mobile or embedded device use. A reduced version of
the framework, the .NET Compact Framework, is available on Windows CE
platforms, including Windows Mobile devices such as smartphones. Additionally,
the .NET Micro Framework is targeted at severely resource-constrained devices.
Version
|
Version
Number
|
Release
Date
|
Visual
Studio
|
Default
in Windows
|
1.0
|
1.0.3705.0
|
2002-02-13
|
Visual Studio .NET
|
Windows XP Tablet and Media Center
Editions.
|
1.1
|
1.1.4322.573
|
2003-04-24
|
Visual Studio .NET 2003
|
Windows Server 2003
|
2.0
|
2.0.50727.42
|
2005-11-07
|
Visual Studio 2005
|
Windows Server 2003 R2
|
3.0
|
3.0.4506.30
|
2006-11-06
|
Windows Vista, Windows Server 2008
|
|
3.5
|
3.5.21022.8
|
2007-11-19
|
Visual Studio 2008
|
Windows 7, Windows Server 2008 R2
|
4.0
|
4.0.30319.1
|
2010-04-12
|
Visual Studio 2010
|
Windows 7(Recommended)
|
4.5
|
4.5.40805
|
2012-02-29 (consumer preview)
|
Visual Studio '11'
|
Windows 8, Windows Server 8
|
Design
features
Interoperability
Because computer systems commonly require interaction
between newer and older applications, the .NET Framework provides means to
access functionality implemented in programs that execute outside the .NET
environment. Access to COM components is provided in the
System.Runtime.InteropServices and System.EnterpriseServices namespaces of the
framework; access to other functionality is provided using the P/Invoke
feature.
Common Language Runtime Engine
The Common Language Runtime (CLR) is the execution engine of
the .NET Framework. All .NET programs execute under the supervision of the CLR,
guaranteeing certain properties and behaviors in the areas of memory
management, security, and exception handling.
Language Independence
The .NET Framework introduces a Common Type System, or CTS.
The CTS specification defines all possible datatypes and programming constructs
supported by the CLR and how they may or may not interact with each other
conforming to the Common Language Infrastructure (CLI) specification. Because
of this feature, the .NET Framework supports the exchange of types and object
instances between libraries and applications written using any conforming .NET
language.
Base Class Library
The Base Class Library (BCL), part of the Framework Class
Library (FCL), is a library of functionality available to all languages using
the .NET Framework. The BCL provides classes that encapsulate a number of
common functions, including file reading and writing, graphic rendering, database
interaction, XML document manipulation, and so on.
Simplified Deployment
The .NET Framework includes design features and tools which
help manage the installation of computer
software to ensure it does not interfere with previously installed software,
and it conforms to security requirements.
Security
The design is meant to address some of the vulnerabilities,
such as buffer overflows, which have been exploited by malicious software.
Additionally, .NET provides a common security model for all applications.
Portability
While Microsoft has never implemented the full framework on
any system except Microsoft Windows, the framework is engineered to be platform
agnostic, and cross-platform implementations are available for other operating
systems (see Silverlight and the Alternative implementations section below).
Microsoft submitted the specifications for the Common Language Infrastructure
(which includes the core class libraries, Common Type System, and the Common
Intermediate Language), the C# language and the C++/CLI language to both ECMA
and the ISO, making them available as official standards. This makes it
possible for third parties to create compatible implementations of the
framework and its languages on other platforms.
Monday, 12 March 2012
Count Number of Visitors in WebSite using ASP.Net and C#
RightClick in Solution Explorer>> Addnewitem>>
Like this
Write Code in Global.asax file
<%@ Application Language="C#" %>
<script runat="server">
public static int count = 0;
void Application_Start(object sender, EventArgs e)
{
Application["myCount"] = count;
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
count = Convert.ToInt32(Application["myCount"]); Application["myCount"] = count + 1;
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
|
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Hitcounter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32((Application["myCount"]));
Label1.Text = Convert.ToString(a);
if (a < 10)
Label1.Text = "000" + Label1.Text;
else if (a < 100)
Label1.Text = "00" + Label1.Text;
else if (a < 1000)
Label1.Text = "0" + Label1.Text;
}
}
|
Disabling the back button Of Browser using ASP.NET
How to disable browser's Back button in ASP.NET
Almost every ASP.NET developer face this problem at least once in his entire career. There could be numerous reasons for disabling the browser's back button. The site is secure and the user should not be allowed to go back to the previous page, for online exams site the student should be not allowed to view the question once answered etc could be the reasons for disabling the back button.
What does the browser back button actually do?
The browser maintains a cache of the pages that are visited by the user. Once the user clicks on the back button, the browser flushes the cached version of the page. Now to avoid this situation we can think of two solutions
1. Whenever the user clicks on the "back" button, again redirect the user to the "next" page using the JavaScript: history.forward(1). This JavaScript needs to be written on the onload JavaScript event of the web page. Thus the user will never be able to come to the previous page. But this is not a reliable technique since some of the browser's do not invoke the onload function on pressing the "Back" button.
2. Another solution is to avoid the browser maintaining the cache of the pages that a user visits. Yes, this can be achieved through AsP.NET server side coding. Add the following code to the Page_Load event of ASP.NET web page or MasterPage:
// Disable the Cache Response.Buffer= true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = “no-cache”; // Check for your SessionID if(Session["SessionId"] == null) { Response.Redirect (”Home.aspx”); }
This code will disable the cache for the current page. The pages contents are maintained in memory i.e. in buffer. Once the user logout the session and buffer will be cleared. As we are not maintaining the cache for the page, the back button will not work anyways. It means we have successfully disabled the Back button.
FileUpload control in ASP.NET
With ASP.NET, accepting file uploads from users has become extremely easy. With the FileUpload control, it can be done with a small amount of code lines, as you will see in the following example. However, please notice that there are security concerns to to consider when accepting files from users! Here is the markup required:
<form id="form1" runat="server"> <asp:FileUpload id="FileUploadControl" runat="server" /> <asp:Button runat="server" id="UploadButton" text="Upload"
onclick="UploadButton_Click" /> <br /><br /> <asp:Label runat="server" id="StatusLabel" text="Upload status: " /> </form>
And here is the CodeBehind code required to handle the upload:
protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded.
The following error occured: " + ex.Message; } } }
As you can see, it's all relatively simple. Once the UploadButton is clicked, we check to see if a file has been specified in the upload control. If it has, we use the FileUpload controls SaveAs method to save the file. We use the root of our project (we use the MapPath method to get this) as well as the name part of the path which the user specified. If everything goes okay, we notify the user by setting the Text property of the StatusLabel - if not, an exception will be thrown, and we notify the user as well.
This example will get the job done, but as you can see, nothing is checked. The user can upload any kind of file, and the size of the file is only limited by the server configuration. A more robust example could look like this:
protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less
than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded.
The following error occured: " + ex.Message; } } }
Here we use the two properties, ContentLength and ContentType, to do some basic checking of the file which the user is trying to upload. The status messages should clearly indicate what they are all about, and
you can change them to fit your needs.
Tuesday, 28 February 2012
Source code of google map in asp.net
Place google map key in web config file
example:
After </system.web> tag
<appSettings>
<add key="googlemaps.subgurim.net" value="ABQIAAAA9962__pKzjVwwD2OKjGyvBTqD8KII8nGCHEOs63QpaP31mkaURSGwkaJxV2dbdG8nnV83KE_FGQ_vg"/>
</appSettings>
string strFullAddress;
string address="punjab";
string sMapKey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
Subgurim.Controles.GeoCode GeoCode;
strFullAddress = address + ". " + ". " + "India";
GeoCode = GMap1.geoCodeRequest(strFullAddress);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
Subgurim.Controles.GMarker oMarker = new Subgurim.Controles.GMarker(gLatLng);
GMap1.addGMarker(oMarker);
example:
After </system.web> tag
<appSettings>
<add key="googlemaps.subgurim.net" value="ABQIAAAA9962__pKzjVwwD2OKjGyvBTqD8KII8nGCHEOs63QpaP31mkaURSGwkaJxV2dbdG8nnV83KE_FGQ_vg"/>
</appSettings>
string strFullAddress;
string address="punjab";
string sMapKey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
Subgurim.Controles.GeoCode GeoCode;
strFullAddress = address + ". " + ". " + "India";
GeoCode = GMap1.geoCodeRequest(strFullAddress);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
Subgurim.Controles.GMarker oMarker = new Subgurim.Controles.GMarker(gLatLng);
GMap1.addGMarker(oMarker);
Subscribe to:
Posts (Atom)
