Browse
 
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 asp.net 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).

asp.net 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"%> 
<html> 
<head> 
<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
Try
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
</script>

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