ASP.NET Developers Guides

1.O’Reilly – ASP .NET in a Nutshell (2nd Ed.)
O'Reilly - ASP .NET in a Nutshell (2nd Ed.)

Click here to Download

2.Pro ASP.NET in C# 2005
Pro ASP.NET in C# 2005

Click here to Download

Creating a File-Upload User Control with ASP.NET

Introduction

This Program explains how to create a file-upload user control in ASP.NET. This will show how to save the uploaded file to disk without granting anonymous users file-write access to folders on your Web server. Finally, you’ll wrap all this in a new ASP.NET user control. This will allow you to add file upload capabilities to almost any Web page quickly and easily.

The .NET Framework offers the FileUpload control to simplify uploading files from web pages.

For this example, we will need to first import the System.Web.UI.WebControls namespace. The System.Web.UI.WebControls namespace contains the classes we need to extract the filename of the file we wish to upload.

using System.Web.UI.WebControls

1.Create a New Website in asp.net prepared language C#.

2.Add Controls to the Design page.untitled1

Now we can write C# code within the UploadFile method to save the uploaded file in the server. This code can be written in two ways depending on the number of file controls we have within the page. If there is only a single file control then we can use the PostedFile property of the file control to upload files. This property is of type HttpPostedFile class and contains the following methods and properties which aids file uploading.

Properties
Property Description
FileName Returns the full path and name of the uploaded file.
ContentType The MIME type of the uploaded file.
ContentLength The size in bytes of the uploaded file.
Method
Methods Description
SaveAs(Path) Saves the uploaded file to the specified path.

If we have multiple file controls within the form we can use the Files property of the Request object which returns a reference to the HttpFileCollection class. HttpFileCollection class has an Item property through which gets individual HttpPostedFile from the file collection either by specifying the name or index.

Finally, you need to add the event handler for the button click. This is the code that does the actual uploading of the file. Actually, there is very little code needed to do this. I

filename.PostedFile.SaveAs(sPath+savename.Value);

This line uses the name of the control (filename) and accesses the PostedFile object’s SaveAs method to pass the path and filename of the file to save. However, to make the control a bit more robust, you’ll add some server-side content checking and then some code to pull the actual file size, type, and location from the PostedFile object. Finally, you’ll wrap the call to the SaveAs method in a try…catch block and display an appropriate status message based on the results.Add the given code to Button1_Click method referred to in the OnServerClick attribute of the button control. Below is the complete code block for the event handler.


protected void Button1_Click(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e) { // make sure there is a file to upload if (SaveAs.Text == "") { Label1.Text = "Missing a 'save as' name."; }
// try save the file to the Disk if (FileUpload1.PostedFile != null) { //build File information for display string path = UploadFolder; string info = "<br>File Name:" + FileUpload1.PostedFile.FileName + "<br>ContentType:" + FileUpload1.PostedFile.ContentType + "<br>ContentLenth:" + FileUpload1.PostedFile.ContentLength.ToString() + "<br>GetType:" +FileUpload1.PostedFile.GetType(); try { FileUpload1.PostedFile.SaveAs(path + SaveAS.Text); Label1.Text = "File Upload Status:" + info; } catch (Exception err) { Label1.Text="<br>Error:"+err; } } }

When you actually run the test page you can select a file, set the “SaveAs” name, and press the button to send the file to the server. If you’re successful, you’ll see a message like the one in the screenshot below.

Output Window

untitled

.NET Framework Essentials by O’Reilly Media

Here is a cool document that i found about .NET Framework

Master Page.

Master Pages enables you the developer to create a consistent look and feel for your web application. For most of us, we either create a header and footer on each and every webpage or we create a header and footer control and then add those controls to each and every .aspx page.

A master page is similar to a ‘.aspx’ page except that it has its own unique extension, ‘.master’. Furthermore, a master page contains a new ‘Master’ directive, along with a ContentPlaceHolder control

Master pages give your site a steady look and feel

Master pages contain both HTML and a code part and it create a common template that can be used on many pages

Updating the master page automatically updates all pages using it

A master page has 2 parts

  1. Content that appears on each page that inherits the master page
  2. Regions that can be customized by the pages inheriting the master page

Master pages can contain HTML, Web controls and server side source code

To Add a Master Page in the application follow the steps
1: Right Click Solution Explorer | Select Add New Item. This will give the following dialog box (see Figure 1):

Select Master Page and click Add. Master Page will be added to your website

workingMasterPages_clip_image003

Master pages end with .Master. By default visual studio names the master page masterPage.master

A Master page need to specify both the parts common to all pages and the parts that are customizable

Items you add to the master page appear on all pages that inherit it

Use contentPlaceHolder controls to specify a region that can be customized

Add a table to the Master page

After creating the master page, notice that it looks like any other page, but it uses a new directive called <%@ Master %>:

<%@ Master Language="C#" 
   CompileWith="MasterPage.master.cs"
   AutoEventWireup="false" 
      ClassName="MasterPage_master" %>

You can also place default content within the ContentPlaceHolder:

<asp:contentplaceholder 
   id="BasicContentPlaceHolder" 
   runat="server">
   No default content specified
</asp:contentplaceholder>

workingMasterPages_clip_image007

It adds on ContentPlaceHolder by default

If you place controls outside the content placeholders they will be displayed on all pages

2.Right Click the Solution Explorer and select Add New Item and Select Web Form and Check Select Master Page

workingMasterPages_clip_image009

From the Select a Master Dialog, select the master page and click OK

  • Select the master page you created.

All masterpages in your site will appear

workingMasterPages_clip_image011

All is grayed out except the contentPlaceHolder control

You can only add controls to and modify inside the ContentPlaceHolder

You can only add controls to and modify inside the ContentPlaceHolder

The purpose of a master page is to define a template for the website

Master pages contain a default contentPlaceHolder control when you create

Which is Hot ??? DotNet or Java

Java and Microsoft .NET are two frequently used Development environment to build Web Applications.Many Developers treat their development platform as religion and its really a difficult to judge who will be the winner.Both Java and .NET adopts a different approach.Java’s tagline has been “Write Once run anywhere…”. and if Microsoft had one it could have

Famous websites for Dotnet Programmers

Hi all,

here i mentioned the important websites for the dot-net programmers who are searching for the job and who are already doing job.

1)http://www.dotnetspider.com

this site is for dot-net interview questions,jobs,tutorials,articles and it has the demo projects.This is very useful for the freshers to read the articles and tutorials and to see the demo projects

2)HTTP://forums.asp.net

It is a dot-net forum.this is best for the experienced programmers.They can post their doubts in this forum and get their answers within a short time.

3)http://www.w3schools.com

This site is famous for the web-technologies.This is useful for the Freshers.This site consists of HTML,XML,ASP,ASP.NET,SQL,JAVA SCRIPT.

and other important sites are

4) http://www.gotdotnet.com

this site consists of with demo programs

5) http://www.codeproject.com

this site consists of total c# coding and asp.net

6) http://aspnet.4guysfromrolla.com

This site is also very useful for the DotNet Developers.

Why .NET?

Some advantages that .NET has over Java are:

  1. Java is not just a platform, but a language. .NET is language independent. Adopting .NET does not force you to adopt a single, or even specific language. .NET can even support the Java language, and J# is very close to Java.
  2. Language interoperability.
  3. .NET can coexist with and even integrate with existing Win32 code.
  4. Moving to Java from Win32 is a complete paradigm shift. Moving to .NET is a more natural path for Win32 developers.

Please go through this article about the comparison between dotnet and java

http://www.codeproject.com/dotnet/WhyDotNET.asp