C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to upload a file to a Web server in ASP.NET by using c# (C Sharp)


Posted Date: 30 May 2006    Resource Type: Articles    Category: .NET Framework
Author: krishna reddy yerramMember Level: Bronze    
Rating: Points: 7



Modify the WebForm1.aspx page
To modify the HTML code of the WebForm1.aspx file to permit users to upload files, follow these steps:
1. Return to the open instance of Visual Studio .NET. WebForm1.aspx should be open in the Designer window.

2. To view the HTML source of the WebForm1.aspx page, right-click WebForm1.aspx in the Designer window, and then click View HTML Source.

3. Locate the following HTML code, which contains the tag:

4. Add the enctype="multipart/form-data" name-value attribute to the "form" tag in the HTML source as follows:< form id="Form1" method="post" enctype="multipart/form-data" runat="server" / >





5. Verify that the HTML tag appears as follows:
< form id="Form1" method="post" enctype="multipart/form-data" runat="server">
< INPUT type=file id=File1 name=File1 runat="server" />
< br>
< input type="submit" id="Submit1" value="Upload" runat="server" />
< / form>

Add the upload code to the WebForm1.aspx.vb code-behind file
protected void Submit1_ServerClick(object sender, EventArgs e)
{

if (File1.PostedFile != null && File1.PostedFile.ContentLength > 0)
{
String fn = null;
fn = System.IO.Path.GetFileName( File1.PostedFile.FileName);
String SaveLocation = null;
SaveLocation = Server.MapPath(fn);
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
else
{
Response.Write("Please select a file to upload.");
}}

Upload larger files

By default, ASP.NET permits only files that are 4,096 kilobytes (KB) (or 4 megabytes [MB]) or less to be uploaded to the Web server. To upload larger files, you must change the maxRequestLength parameter of the section in the Web.config file.

Note When the maxRequestLength attribute is set in the Machine.config file and then a request is posted (for example, a file upload) that exceeds the value of maxRequestLength, a custom error page cannot be displayed. Instead, Microsoft Internet Explorer will display a "Cannot find server or DNS" error message.

If you want to change this setting for all of the computer and not just this ASP.NET application, you must modify the Web.config file.

By default, the element is set to the following parameters in the Web.config file:
< httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100" />





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Uploading and Downloading files using ASP.NET
Previous Resource: Implementing Datatable in Combo Box Control
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use