C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

File Upload


Posted Date: 03 Jan 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: Nikhil AgarwalMember Level: Gold    
Rating: 1 out of 5Points: 5



A typical HTML and C# code sample that uses the old HtmlInputFile control to upload a file.
please find code in attachment file

void btnSave_Click(object sender, EventArgs e)
{
// Other validation code

if (ctlFile.PostedFile.FileName == "")
// display some sort of error
else
ctlFile.PostedFile.SaveAs("C:\\Inetpub\\wwwroot\\
somefilename.dat");

// Other code to handle save routine
}

The new FileUpload control replaces the old control very easily. The new HTML looks like this:
please find code in attachment file

You can use the new HasFile property of the control to indicate whether the user had selected a file to upload. This simplifies the validation code a bit, as shown here:

void btnSave_Click(object sender, EventArgs e)
{
// Other validation code

if (!ctlFile.HasFile)
// display some sort of error
else
ctlFile.PostedFile.SaveAs("C:\\Inetpub\\wwwroot\\
somefilename.dat");

// Other code to handle save routine
}




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
File Upload  .  

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: how to use trim function
Previous Resource: How Get Information About A File
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use