• The eternal confessions of a beautiful mind...
  • DamianM.Co.UK
  • Home
  • About
  • Archives
  • Contact
  • Sitemap
  • My Flickr

    IMG_9585IMG_9115IMG_9113IMG_9111IMG_9078IMG_9075IMG_9069IMG_9065IMG_9041IMG_9032IMG_8963IMG_8928IMG_8916IMG_8915IMG_8904IMG_8876IMG_8858IMG_8830IMG_8828IMG_8826

  • Recent Posts

    • New Ohio Roller Coaster - INSANE!!!
    • Speeding
    • Captions not required
    • Unfortunate Backgrounds
    • Unfortunate Signs
    • OMG!!
    • Women as explained by engineer
    • The Monty Hall Problem
    • ahhh still love them - Motivational Posters
    • What does Mona Lisa do when the Museum is closed………
    • 21st Century kids books
    • Cool Origami
    • AWESOME Pictures!
    • Things you shouldn’t find in your vegetable patch!
    • World’s Best Graffiti…?
  • My Tools

    • Blog_LinkIt
    • DCoda Theme
    • DCoda Widgets
    • RSS_Sticky
    • WordPress.org
    • WP_BlogNetworking
    • WP_BlogRollSync
    • WP_BoilerPlate
    • WP_Censor
    • WP_ContactMe
    • WP_DeliciousPost
    • WP_EasyReply
    • WP_HeadNFoot
    • WP_LinkIt
    • WP_OneInstall
    • WP_PostDate
    • WP_PostNotes
    • WP_RssSticky
    • WP_Spoiler
    • WP_Submission
  • My Web

    • ASPAlliance
    • ClaimID
    • del.ico.us
    • Digg
    • DSLRBlog
    • DVDProfiler
    • Flickr
    • Honeyed SPAM
    • My Blog
    • My company
    • MYSpace
    • WordPress.org
    • YouTube

    Upload

    Upload.aspx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    
    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="upload.aspx.vb" Inherits="DamianM.upload" enableViewState="False" %>
    <form id="Form1" method="post" runat="server" enctype="multipart/form-data" action="/code/2/upload.aspx">
    	<center>
    		<table border="0">
    			<tr>
    				<td>
    					Upload File
    				</td>
    			</tr>
    			<tr>
    				<td>
    					<INPUT type="file" id="upload" name="upload" size="40"> <INPUT type="submit" value="Submit">
    				</td>
    			</tr>
    			<tr>
    				<td>
    					<font color="red">
    						<asp:Literal id="ErrorMsg" runat="server"></asp:Literal></font>&nbsp;
    				</td>
    			</tr>
    			<tr>
    				<td>
    					File Contents
    				</td>
    			</tr>
    			<tr>
    				<td>
    					<TEXTAREA rows="5" cols="50"><asp:Literal id="FileContents" runat="server"></asp:Literal></TEXTAREA>
    				</td>
    			</tr>
    			<tr>
    				<td>
    					File Link
    				</td>
    			</tr>
    			<tr>
    				<td>
    					<asp:Literal id="FileLink" runat="server"></asp:Literal>
    				</td>
    			</tr>
    		</table>
    	</center>
    </form>

    Upload.aspx.vb

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    
    Imports System
    Imports System.Web
    Public Class upload
        Inherits System.Web.UI.UserControl
        Protected WithEvents ErrorMsg As System.Web.UI.WebControls.Literal
        Protected WithEvents FileLink As System.Web.UI.WebControls.Literal
        Protected WithEvents FileContents As System.Web.UI.WebControls.Literal
     
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            Dim File As HttpPostedFile
     
            ErrorMsg.Text = ""
            FileLink.Text = "(none)"
            FileContents.Text = ""
            'check that a file has been uploaded
            If Request.Files.Count <= 0 Then
                ErrorMsg.Text = "No file was uploaded"
            Else
                'get the file data
                File = Request.Files.Get(0)
                'check thats its not too big
                If File.ContentLength > 1024 Then
                    ErrorMsg.Text = "File is bigger than 1k"
                Else
                    If File.ContentType <> "text/plain" Then
                        ErrorMsg.Text = "File is not a text file"
                    Else
                        'save file
                        File.SaveAs(Server.MapPath("..\..\files\upload\deleteme.txt"))
                        'show link
                        FileLink.Text = "<a href=""../../files/upload/deleteme.txt"">" + File.FileName + "</a>"
     
                        'open in out stream 
                        Dim sr As System.IO.StreamReader
                        Dim strContent As String
                        sr = New System.IO.StreamReader(File.InputStream)
                        'display contents
                        FileContents.Text = sr.ReadToEnd
                        sr.Close()
     
                    End If
                End If
            End If
        End Sub
     
     
    End Class

    One Response to “Upload”

    1. DamianM » Blog Archive » File uploading with .NET Says:
      June 14th, 2007 at 7:22 pm

      [...] Upload Source Code [...]

    Leave a Reply

    Related Posts from the Past:

    • File uploading with .NET
    • Everything's shaping up