Library code snippets
Uploading Files Using ASP.NET
Add a file browse HTML control. Right click and select 'Run as Server Control'. Add a button. So you have something like this:
<input type="file" runat="server" ID="File1" /><asp:Button runat="server" ID="Button1" />
Double click the button and add the following code.
private void Button1_Click(object sender, System.EventArgs e)
{
string strFilename;
try
{
strFilename = File1.PostedFile.FileName;
strFilename = System.IO.Path.GetFileName(strFilename);
File1.PostedFile.SaveAs(@"f:\"+strFilename);
}
catch(Exception ex)
{
Response.Write(ex);
}
}
Related articles
Related discussion
-
Sheduling and sending mails asp.net
by mr_rajesh86 (0 replies)
-
asp.net add datarow to existing dataset table
by janetb (1 replies)
-
Buy cheap Xanax overnight. Cheap Xanax. Overnight delivery of Xanax in US no prescription needed. Cheapest Xanax.
by asleymar (0 replies)
-
Buy Soma online without a prescription. Soma drug no prescription. How to get Soma prescription. Soma cod accepted.
by asleymar (0 replies)
-
Cheap online order Fioricet. Cheap discount Fioricet. Offshore Fioricet online. How to buy Fioricet online without a prescription.
by asleymar (0 replies)
Related podcasts
-
StackOverflow uses ASP.NET MVC - Jeff Atwood and his technical team
Scott chats with Jeff Atwood of CodingHorror.com and most recently, StackOverflow.com. Jeff and Joel Spolsky and their technical team have created a new class of application using ASP.NET MVC. What works, what doesn't, and how did it all go down?
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
Write permission must be given to upload folder for the asp.net account.
!--removed tag-->Have you solved this problem? You might need to change the file right access right property for the folder and/or for the file.
What exactly is at line 56?
System.UnauthorizedAccessException: Access to the path "d:\build_info" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at WebApplication1.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\webform1.aspx.cs:line 56
what is this problem means??
In Web.config change the value of maxRequestLength ...
Example (for 100mb):
<httpRuntime maxRequestLength="100000" />
but this code cannot upload huge file size and this is a big problem for me
hi,
Nice piece of code..
I have a requirement where i need to upload a file to another system in the LAN.
I have an ftp appication which does this for me. But i need to do it from ASP.NET itself..
Is there a way to enhance the above code to transfer files across systems
or can i call my ftp application from ASP.NET ?
My ftp application is written in VB.
Thanks in Anticipation.
kris.
This thread is for discussions of Uploading Files Using ASP.NET.