Tools Add
Rss Categories

ASP.NET Upload

Reference Number: AA-00477 Created: 2012-09-19 14:55 Last Updated: 2012-10-02 05:21 0 Rating/ Voters

ASP.NET form to upload files to your Windows 2008 site

Here is a sample upload script that will work on our Windows 2008 servers. You can copy it into a text file and rename it upload.aspx then upload it to your site space. It is currently set to upload a given file to a folder called "uploads" so you'll need to create that folder and give it write permissions (this can be done through your onCloud control panel). script

You will need to copy and paste the script below into your favorite text editor and save it as upload.aspx (or any name of your choosing with and .aspx extension). You can then upload the script anywhere within your /wwwroot folder. You also need to create a folder in your /wwwroot folder called uploads.

<%@ Import namespace="System.IO"%> 
<title>Uploading a File</title>  
<script language="VB" runat="server">

Sub Upload_Click(source As Object, e As EventArgs)
If Not (uploadedFile.PostedFile Is Nothing) Then
Dim postedFile = uploadedFile.PostedFile
Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength

postedFile.SaveAs(Server.MapPath("~") & "uploads\" & filename)
message.Text = postedFile.Filename & " uploaded" & _
"<br>content type: " & contentType & _
"<br>content length: " & contentLength.ToString()
Catch exc As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub

<form enctype="multipart/form-data" runat="server"> 
Select File to Upload:  
<input id="uploadedFile" type="file" runat="server"> 
<input type=button id="upload"  
<asp:Label id="message" runat="server"/> 
Rss Comments
  • There are no comments for this article.
Info Add Comment
Nickname: Your Email: Subject: Comment:
Enter the code below: