Results 1 to 2 of 2

Thread: file uploading help... should be simple

  1. #1

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727

    file uploading help... should be simple

    hi all,

    i'm currently uploading a file using the typical code:
    Code:
    <%@ Import namespace="System.IO"%>
    <html>
    <head>
    <title>Uploading a File</title> 
    <script language="VB" runat="server">
    
    Dim savePath As String = "C:\temp\"
    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(savePath & 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>
    my problem is the following: i need the FORM to be on one STATIC page (html), and when that page is submitted, the form action is a .aspx file which will get the uploaded file.

    ...how can i do this? i'm really stuck on this one.

    thank you in advance,

    wc.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: file uploading help... should be simple

    I've never tried it myself but the Request object has a Files property which returns a HttpFileCollection. I'm presuming this would be a collection of uploaded files which could be dealt with in the same way.

    Try using this:
    Code:
    <%@ Import namespace="System.IO"%>
    <html>
    <head>
    <title>Uploading a File</title> 
    <script language="VB" runat="server">
    
    Dim savePath As String = "C:\temp\"
    Sub Upload_Click(source As Object, e As EventArgs)
    
      If Not (Request.Files["uploadedFile"] Is Nothing) Then
        Try
          Dim postedFile = Request.Files["uploadedFile"]
          Dim filename As String = Path.GetFileName(postedFile.FileName)
          Dim contentType As String = postedFile.ContentType
          Dim contentLength As Integer = postedFile.ContentLength
    
          postedFile.SaveAs(savePath & 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>
    DJ

    If I have been helpful please rate my post. If I haven't tell me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width