Library code snippets
Uploading Files Using ASP.NET
By Man from Mars, published on 27 Feb 2006
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
-
sharepoint calendar web part with events from sql table
by tukubapi2207 (1 replies)
-
Using FedEx Web Service to Calculcate Shipping Cost
by bhora123 (4 replies)
-
Very Urgent regarding deleting the images from a folder
by rameshbandi (2 replies)
-
Dynamically Generating PDFs in .NET
by nike12 (10 replies)
-
New style of Javascript used in extenders.
by mittalpa (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?
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.