Site Meter Asp.Net-Csharp,Asp,Ado.Net,Ado,Micosoft,Visualstudio,Visual webgui: 2009

Friday, December 11, 2009

Overview and example for Datatable in asp.net

Overview and example for Datatable in asp.net:


MEthod 1:


DataTable cTable = new DataTable();
DataRow d3;

cTable.Columns.Add("A", typeof(string));
cTable.Columns.Add("B", typeof(string));
cTable.Columns.Add("C", typeof(string));

d3 = cTable.NewRow();
d3[0] = "A:";
d3[1] = B;
d3[2] = "C";

cTable.Rows.Add(d3);


Method 2:

DataTable dtProducts = new DataTable();
DataColumn productColumn = new DataColumn();

productColumn.DataType = System.Type.GetType("System.Int32");
productColumn.ColumnName = "id";
productColumn.Unique = true;
dtProducts.Columns.Add(productColumn);


DataTable dtProducts = createProductDT();

DataRow aProduct = dtProducts.NewRow();

aProduct["id"] = 11;
aProduct["thumb"] = "images/widget0.jpg";
aProduct["name"] = "Red Widget";
aProduct["price"] = 19.99;
dtProducts.Rows.Add(aProduct);

Wednesday, December 9, 2009

Types,Modes,Differences of session in asp.net

Overview of session modes and types in asp.net:

Normally http protocol is stateless to maintain state following namespace is used.

System.Web.SessionState.HttpSessionState

Modes And's Provider:

Session State Mode State Provider

InProc In-Memory Object
StateServer Aspnet_state.exe
SQLServer DataBase
Custom CustomProvider

Session Event's:

There are two types of session events available in asp.net

* Session_Start
* Session_End


Types:

1.inproc Mode (ie inprocess)--->Its availble inside the webserver itself not ouside the application.
2.StateserverMode(ie out process) -->Its availble outside the webserver,not inside the application.
3.sqlserver Mode -->To store session datas in sqlserver.AND DATAS CAN BE SHARED BETWEEN OTHE APPLICATIONS.
4.Custom Mode --> To create a manual session id's.



1.inproc Mode

Advantages :

* It store Session data in memory object of current application domain. So accessing data is very fast and data is

easily available.
*Datas not alive when application restarted.
* There is not requirements of serialization to store data in InProc Session Mode.
* Implementation is very easy, just similar to using View State.

DisAdvantage:

If the worker Process or application domain recycles all session data will be lost.


2.StateserverMode

This session state is totally managed by aspnet_state.exe.

This approaches has several disadvantages due to the overhead of serialization and de-serialization.

Datas will be alive it the aspnet services restarted also.


3.sqlserver Mode

The most easiest way to configure SQL Server, is using aspnet_regsql command.

4.Custom Mode --> To create a manual session id's.

Thursday, November 26, 2009

Find client and server ip address in asp.net,C#.

Find client and server ip address in asp.net,C#.

To get Server IP Address and Name(ie)where your domain hosted in an server:


1. string strHostName = System.Net.Dns.GetHostName();
2. string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


To get Client IP address ie system current IP address:

1.Response.Write(Request.ServerVariables["http_user_agent"].ToString());

Your IP address is:
2.Response.Write(Request.ServerVariables["remote_addr"].ToString());

The DNS lookup of the IP address is:
3.Response.Write(Request.ServerVariables["remote_host"].ToString());

The method used to call the page:
4.Response.Write(Request.ServerVariables["request_method"].ToString());

The server's domain name:
5.Response.Write(Request.ServerVariables["server_name"].ToString());

The server's port:
6.Response.Write(Request.ServerVariables["server_port"].ToString());

The server's software:
7.Response.Write(Request.ServerVariables["server_software"].ToString());

Sunday, November 22, 2009

Download application or word or doc or pdf code in asp.net,c#

Download application or word or doc or pdf code in asp.net,c#
if (Page.IsPostBack){

Response.ContentType="application/ms-word";
Response.AddHeader( "content-disposition","attachment; filename=RegistrationFormDownload.pdf");
//Source from server
FileStream sourceFile = new FileStream(@"c:\inetpub\vhosts\www.com\httpdocs\Form.pdf", System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read );
//Source from Local system
FileStream sourceFile = new FileStream(@"system file path", System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read );
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();

Response.BinaryWrite(getContent);
}

Saturday, November 21, 2009

Differences::::Div vs span vs iframe

Differences::::Div vs span vs iframe

Blogger wont allow HTML content you can get full article which is given below from this link.You can download it.. http://www.4shared.com/file/156448190/930b924a/div_vs_frame_vs_span.html


DIV is short for "division" because it divides elements.

span is inline, div a block.span is permitted in a div, but not div in a span.

The main difference is that span element is in-line and usually used for a small chunk of in-line HTML whereas a div (division) element is block-line (which is basically equivalent to having a line-break before and after it) and used to group larger chunks of code.

is a block level element -- it's going to 100% width, and it will line break - and is best used for structure (stands for 'division' -- semantic markup here!)
is inline, it can go next to other elements and is best used for text editing... adding rules to special text in a paragraph, hiding text (like navigation), etc.

Eg;;

The div tag has forced a line break.
The div tag will force a line break.
The div tag has forced a line break.The span tag does not force a line break. There is no line break.


Reference to div tag properties:::: http://www.searchwin.net/spandiv.htm


IFrame and Div are HTML tags. They are only for the layout purposes. Using IFrame, you can view another html file in your main html.
Div is used to display contents in a html page. You can put some text,image, and/or combination to display in a div.

An iframe is like having a hole on your page, and in that hole is another web page. If that page is clicked ONLY that page will refresh so that the rest of the site appears to stay in the same place. It's not valid HTML and is therefore not encouraged because browsers can interpret iframes however they want. An iframe is only a container and the page that goes inside it still needs to be written as usual.

To get small idea to get what is div tag

#framearea {
width: 550px;
height: 150px;
margin-bottom: 10px;
}
.framebody {
overflow: auto;
width: 550px;
height: 150px;
}

...content here...



Using a DIV as variable to write into IFRAME


http://www.devarticles.com/c/a/HTML/The-power-of-DIV-with-IFRAME/

Saturday, November 14, 2009

Installing windows Azure ,

Installing windows Azure SDK7

Prerequist:2
IIS 7.0 has to be configured in Vista.8
ASP.NET Application Development components installed.2

WPIlauncher install(Microsoft Web Platform Installer 2.0 Beta)4

Click on the Web Platform tab and customize the Web Server option with:
ASP.Net, Default Document and CGI (if you want to run fastCGI apps)

Click “Install” when you are ready. You’ll get an opportunity to review your selection,
then the download and install will commence.

Finally, if you are using WCF, you will want to install WCF HTTP Activation. (this is a .Net feature)

On Vista: From the Start menu, choose Settings | Control Panel | Programs | Programs and Features,
Click Turn “windows Features On or Off”, under Microsoft .Net Framework 3.0, select WCF HTTP Activation

On Windows Server 2008 – In Server Manager under Features Summary, choose Add Features – under .Net Framework 3.0 Features, select WCF Activation.

Install the Windows Azure Tools

http://www.microsoft.com/downloads/details.aspx?FamilyID=8d75d4f7-77a4-4adf-bce8-1b10608574bb&displaylang=en

What is Localization,Resource,resx in asp.net,C#.

Please refer the following sites to get idea about What is Localization,Resource,resx in asp.net,C#.


http://www.c-sharpcorner.com/UploadFile/prasham/RESOURCEFILES02132008080733AM/RESOURCEFILES.aspx(About Resource file .resx)

http://www.codeproject.com/KB/aspnet/LocalizationPackage.aspx(about localize)

http://www.west-wind.com/presentations/wwDbResourceProvider/introtolocalization.aspx(Example for localize and resource file)

To retrieve table data using table column in asp.net,C#

SqlDataReader rdr = null;
SqlConnection sqlcon = new SqlConnection("Server=___;Initial Catalog=____;Integrated security=true");
sqlcon.Open();

SqlCommand cmd1 = new SqlCommand("select * from ____;", sqlcon);
rdr = cmd1.ExecuteReader();
while (rdr.Read())
{
string ___ = rdr.GetString(rdr.GetOrdinal("column name"));
string ___ = rdr.GetString(rdr.GetOrdinal("column name"));

}
sqlcon.Close();

Substring in asp.net,c#

To find the last character in a string
string lastCharacter = myString.Substring(myString.Length - 1, 1);
//i.e. the last character is a SubString of myString, one character long, starting one character short of the length of myString

To remove the last two characters of a string
string myNewString = myString.Substring(0, myString.Length - 2);
//i.e. the new string is a SubString 2 characters shorter than myString, starting at the beginning of myString

Tuesday, October 27, 2009

Difference between Repeater , Datalist, DataGrid(or GridView)

Difference between Repeater , Datalist, DataGrid(or GridView)



Repeater :

It contains Header Template, Item template , alternate
Item template and footer template . it can't support
Selection, editing, sorting and paging. this is read only
and fast.


Datalist :

It contains Header Template, Item template , alternate
Item template , Edit itm template and footer template . it
can't support sorting and paging but support selection and
editing


DataGrid(or GridView) :

It contains Header Template, Item template , alternate Item
template , Edit itm template and footer template . it can
support selection, editing , sorting and paging . Mostly
every developer caught used this control.

http://forums.asp.net/p/1072020/2217049.aspx

Datagrid vs Gridview

In datagrid you cannot set a permisiion level........

In gridview you can do the access level............

GridView is a composite data-bound control and shares a common set of methods and properties with all other data-bound controls, including DropDownList, DetailsView, and ListBox.

GridView can render on mobile devices.

Grid view Control take care automatically deletes or updates records from the datasource.

Sunday, October 25, 2009

Gridview Rowdatabound.

Gridview Rowdatabound:

DataKeyNames="id" OnRowDataBound="GridView1_RowDataBound"

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

if (e.Row.RowType == DataControlRowType.Pager)
{
e.Row.Cells[1].Text = "RS. " + e.Row.Cells[1].Text;
}


Thursday, October 22, 2009

sql connection string in asp.net

Connetion string used for mssql server which is installed in you server.

SqlConnection sqlcon = new SqlConnection("data source=localhost;Initial Catalog= ur database name; User Id=XXX; Password=XXX");

Connetion string used for mssql server which is installed in you system(ie .sql
server management studio express)


SqlConnection sqlcon = new SqlConnection("Server=.\\SQLExpress;Initial Catalog=ur database name; User Id=XXX; Password=XXX; Integrated security=true");

Calendar Control in Asp.net.

Calendar Control:



TO get calendar selected value to textbox:

this.shippeddate.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;

Validation control in asp.net

RegularExpressionValidator-To accept only numbers

ValidationExpression="[0-9]*">

RegularExpressionValidator-To accept only characters not numbers.

ValidationExpression="[a-z]*[A-Z]*">

RegularExpressionValidator- Expression to get minimum value and maximum value from the user

ValidationExpression="^([\S\s]{1,7})$">

Monday, October 12, 2009

SilverLight 3.0 Features.

Silverlight 3.0 Features:

1.SLOOB(SilverLight out of browser).

Its like a java Applet(Application embedded into browser).but in silverlight we can get that application out of browser and we can use it and access/modify it.After finishing your work you can update it.

We can download that Apllication into your local system by the following ways,

A, Context Menu(By right clicking the app in the browser u can install it in your local system.

B, By the Button click event(Here you can write your program for the installation of Browser App).

There are two main events (Trigger and Network Event)

Network Event:

When you are working in your App(online) if suddenly your connection disconnected it will gives status as its disconnected its done through coding.

Trigger Event:

When you are working in your App(offline) you can update ur app at anytime from the main app(online).By placing the button like install.

SLOOB:

The files or datas what you are working with offline app it wont affect your local system other drives such as c:,d:,etc.....It's mean SECURITY.

It allot separate space for his work that place is ISOLATED STORAGE.

Default size of isolated storage 25MB. But it can extended to what ever size(UNLIMITED).

Difference between DotNet 1.0,2.0,3.0,4.0

DotNet 1.0 = Managed code.
DotNet 2.0 = Generics,ADO.NET.
DotNet 3.0 = Linq(Language Integarated Query),Partial Methods, VAR Keyword.
DotNet 3.5 = WPF,WCF,ASP.NET AJAX.
DotNet 4.0 = Dyanamic Programming.

DotNet 1.0 Understand It:

.Net managed code enjoy's benefits of CLR, which automatically checks for object scope and if it is not referenced by any object than it is removed from memory.

What is the difference between managed and unmanaged code?

Program written in any .net compatible language will go for
compilation for 2times.
In the first compilation of the program, the language
compiler will generate MSIL code which is the managed code. &

the code generated after the second execution ie by the CLR
is called unmanaged code which is machine understandable and
not by the user.

What is MSIL code ?

When the code is compiled, the compiler translates your code
into Microsoft intermediate language (MSIL). The common
language runtime includes a JIT compiler for converting this
MSIL then to native code.
MSIL contains metadata that is the key to cross language
interoperability. Since this metadata is standardized across
all .NET languages, a program written in one language can
understand the metadata and execute code, written in a
different language. MSIL includes instructions for loading,
storing, initializing, and calling methods on objects, as
well as instructions for arithmetic and logical operations,
control flow, direct memory access, exception handling, and
other operations.

DotNet 2.0: Generics,ASP.NET-AJAX.

DotNet 3.0: Understand It:

1.1-->Partial Methods(Refer:http://jalpesh.blogspot.com/2009/07/permanent-redirection-in-aspnet-40.html)

1.2-->LINQ stands for Language-Integrated Query. This means we can use any relational or XML-specific features to our programming languages and runtime. It is a general approach query and provide facilities to the .NET Framework to access any kind of sources of information, not just relational or XML data. It's a Language-Integrated Query to indicate that query is an integrated feature of the developer's primary programming languages (for example, Visual C#, Visual Basic). Language-integrated query allows query expressions to benefit from the rich metadata, compile-time syntax checking, static typing and IntelliSense that was previously available only to imperative code.

The format of the query is more or less simillar to that of SQL. The Select, From, Where clauses are also used here with the same meaning but in different style/location/position. Here is an example of a LINQ program.

using System;
using System.Linq;

class sample
{
static void Main()
{
int[] arrMarks = {78, 90, 56, 45, 89, 23, 67, 93};

IEnumerable Distinction = from m in arrMarks
where m > 70
orderby m
select m;

foreach (int distMark in Distinction)
MessageBox.Show(distMark.ToString());
}
}

DotNet 3.5 Understand It:

WPF = Windows Presentation Foundation.

WPF is the latest in desktop app development in .Net. It features markup based layout much like asp.net. The markup language is XAML. It provides a new way to develop desktop applications keeping UI and logic separate.

WCF = Window Communication Services

WCF is used to communicate between different applications with stuff like services. It is much like web services, but is much more robust and configuration enabled. WCF web services can be configured to act like asmx webservices, or use json or something else. Anything that represents a service can benefit from WCF, such as web services, windows services etc.

DotNet 4.0: Dyanamic Progamming

1.Named and Optional Parameters.(Refer:::http://jalpesh.blogspot.com/search/label/C%23.NET)
2.Integarated COM interop.
3.Co and Contra Variance(Used in interface and delegates).
4.Dyanamic Typed Objects.
5. Response.PermanentRedirect,Page.Keywords and Page.Description Properties for SEO
Refer(http://jalpesh.blogspot.com/2009/07/pagemetadescription-and.html)

Example For Dyanamic Keyword:
http://jalpesh.blogspot.com/2009/11/c-40-dynamic-data-type-difference.html

Thursday, October 8, 2009

free sms webservice to send sms using way2sms

http://www.aswinanand.com/sendsms.php(WEBSERVICE)

By the above web service link any one can able to send free sms through ASP.Net code via way2sms.

Implementation of webservice in our codee:


Before using you should create way2sms account to use this webservice.

Method to add webreference in visual studio:

1.Rt click ur project and click AddWebReference and paste the above top link in it then it will produce xml code below and click ok.

then follow/use the below code

you can write below code in Button event for trial purpose..
com.aswinanand.www.SendSMS sms = new com.aswinanand.www.SendSMS();
sms.sendSMSToMany("ur way2sms username","password","to number","message");

Monday, August 24, 2009

Cookies-State,Session-State,Application-State,QueryString

QueryString:

It's one of way to tranfer datas or values from one aspx page to another.Before knowing query string u should know GET method and POST method.
In Get method u can transfer a values but its limited about 256 characters and u can view it in the address bar example: www.abc.com/a.aspx?s=1
In post method its unlimited values transering so better choose POST method in a form tag.
From the address bar url we get values to the another page.

Application State:

It's one of way to tranfer datas or values from one aspx page to another.But the state or values in the memory were stayed till open -(to) close the application.Application in the sense for eg; Browsers.

Cookies:

It's one of way to tranfer datas or values from one aspx page to another.cookies means a small data ie key value pairs were stored in our local systems and it has been accessed by all other aspx pages.But its not good practice because some of systems ie browsers has not support the function of cookies.Because it were disabled.

Session State:

It's one of way to tranfer datas or values from one aspx page to another.When we talk about session there are many types.But basically means maintaning the state of the user. Example:when user logged into certain site for shopping till he log out the id for him is provided automatically intially..By that id we can track the user and maintain his state till logout.

Mail Settings to send a mail in ASP.NET

using System.Net;
using System.Net.Mail;

SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage();
mail.From = new MailAddress("XXX@gmail.com"); // this is your from mail id
smtp.Credentials = new NetworkCredential("URMAILID", "URPWD");
mail.To.Add("XXXr@gmail.com");
mail.Subject = "YourSubject";
mail.Body = "Mail Body";
mail.ReplyTo = mail.From;
mail.Sender = mail.From;
mail.IsBodyHtml = true;
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
try
{
smtp.Send(mail);
Response.Write("sucess");
}
catch (Exception ex)
{
//lblerror.Text = ex.Message;
}

What made me to create this blog!!!!!

Hello Friends,

Why iam created this blog mean i struggled a lot in the beginning of my career in the field of web development without knowing some basics things basically iam from ECE department.So i decided to give some of the basics needs to the freshers in web development in Dotnet Domain.