Información válida para: planes de Hosting Windows

Puedes subir archivos en el navegador usando ASP. Los siguientes scripts de ejemplo te muestran cómo hacerlo:


MaxLength = x especifica el tamaño máximo del archivo en bytes

        <title>file upload via ASP</title>
<body bgcolor="white">
' --- ASP FileUpload Module GetFILE (C) 1999 by Stefan Falz

' --- Activate error handling
' --- On Error Resume Next
' --- Assign the error source that is to be output if an error occurs.
        Err.Source = "GetFILE HTTP Upload"
' --- Constant for error heading
Const ErrHeader = "<b>Error</b><br><br>"

' --- Declare array
Dim ErrArray(4)
        ErrArray(0) = "10900 - Your sent file is too large."
        ErrArray(1) = "10901 - Unknown error.<br>"
        ErrArray(2) = "10902 - No file has been sent or the transfer is faulty.<br>"
        ErrArray(3) = "10903 - No text file has been sent.<br>"

' -- Call the GetFILE subroutine
        Call GetFILE()

Private Sub GetFile()

' --- The HTTP stream is read in this subroutine.

' --- Declare the variables
Dim FileText
    FileText = Request.BinaryRead(Request.TotalBytes)
Dim FileTextByte
    FileTextByte = """
Dim FileTextNew
    FileTextNew = """
Dim FilePosFirst
    FilePosFirst = 0
Dim FilePosLast
    FilePosLast = 0
Dim FileType
    &lt;font color="#ffff00"&gt;-==- proudly presents
Dim strRevText
    &lt;font color="#ffff00"&gt;-==- proudly presents
Dim strFileName
    &lt;font color="#ffff00"&gt;-==- proudly presents
Dim strFileNameOnly
    &lt;font color="#ffff00"&gt;-==- proudly presents
Dim posFileName
    posFileName = 0
Dim rghFile
    &lt;font color="#ffff00"&gt;-==- proudly presents
Dim lenFileTextByte
    lenFileTextByte = 0

' --- Specify the max. file size + approx. 500 bytes for file information
Dim maxLength
    maxLength = 25500

' --- Query the size of the sent stream
        If Request.TotalBytes > maxLength Then
                Call Error_Handler(10900)
                Exit Sub
        End if

' --- Search for HexCode 0D 0A 0D 0A (beginning of file within HTTP stream)
        FilePosFirst = InStrB(FileText, (ChrB(13) &amp; ChrB(10) &amp; ChrB(13) &amp; ChrB(10)))

' --- Search for HexCode 0D 0A 2D 2D (end of file within HTTP stream)
        FilePosLast = InStrB(FileText, (ChrB(13) &amp; ChrB(10) &amp; ChrB(45) &amp; ChrB(45))

' --- Search for HexCode 2D 0A 0D within the reversed HTTP stream, because under
' --- There may be several end-of-file indicators.
        strRevText = StrReverse(FileText)
        FilePosLast = InStrB(strRevText, (ChrB(45) &amp; ChrB(10)) &amp; ChrB(13))
        FilePosLast = LenB(FileText) - FilePosLast

' --- Abort at file size 0 Byte
        If FilePosFirst = 0 Or FilePosLast = 0 Or FilePosLast - FilePosFirst < 5 Then
                Call Error_Handler(10902)
                Exit Sub
        End If
' --- Cancel if "Content disposition" is not specified
         If InStrB(FileText, ChrB(67) &amp; ChrB(111) &amp; ChrB(110) &amp; ChrB(116) &amp; ChrB(101) &amp; ChrB(110) &amp; ChrB(116) &amp; ChrB(45) &amp; ChrB(84) &amp;  ChrB(121) &amp; ChrB(112) &amp; ChrB(101) &amp; ChrB(58) &amp; ChrB(32) &amp; ChrB(116) &amp; ChrB(101) &amp; ChrB(120) &amp; ChrB(116) &amp; ChrB(47)) = 0 Then
                Call Error_Handler(10903)
                Exit Sub
        End if
' --- Cancel if an error has occurred that is not one of the above errors
        If Err.Number <> 0 Then
                Call Error_Handler(10901)
                Exit Sub
        End if
' --- Determination of the file name incl. path within the HTTP stream
         posFileName = InStrB(FileText, ChrB(102) &amp; ChrB(105) &amp; ChrB(108) &amp; ChrB(101) &amp; ChrB(110) &amp; ChrB(97) &amp; ChrB(109) &amp; ChrB(101) &amp; ChrB(61) &amp; ChrB(34)) + 9

        rghFileText = RightB(FileText, LenB(FileText) - posFileName)

        strFileName = LeftB(rghFileText, InStrB(rghFileText, ChrB(34)) - 1)
                Response.Write "<strong>File name incl. path: </strong>"
                        Response.BinaryWrite strFileName
                Response.Write "<br>"

' --- Determination of the file name excl. path within the HTTP stream
        posLastSlash = InStrB(StrReverse(strFileName), ChrB(92))

        strFileNameOnly = MidB(strFileName, LenB(strFileName) - posLastSlash, posLastSlash + 1)

                Response.Write "<strong>File name excl. path: </strong>"
                        Response.BinaryWrite strFileNameOnly
                Response.Write "<br>"
' --- Cancel if an error occurred
        If Err <> 0 Then
                Call Error_Handler(10901)
                Exit Sub
        End if

' --- Writing the file contents in ByteArray
        FileTextByte = MidB(FileText, (FilePosFirst + 4), (FilePosLast - (FilePosFirst + 4)))

' --- Determining the file size by reading the length of the determined file content
        lenFileTextByte = LenB(FileTextByte)

' --- Conversion of the file content (binary stream) to Ascii characters
        For i = 1 To lenFileTextByte
                FileTextNew = FileTextNew &amp; Chr(AscB(MidB(FileTextByte, i, 1)))

' --- Write the determined file contents to a file.
        Set objFileSys = Server.CreateObject("Scripting.FileSystemObject")
                 Set File = objFileSys.CreateTextFile(Server.MapPath("./") &amp; "\" &amp; Session.SessionID &amp; ".tmp", True, False)
                        File.WriteLine CStr(FileTextNew)
                Set File = Nothing
        Set objFileSys = Nothing

' --- Output the file size in bytes
         Response.Write "<strong>Dateigr&ouml;&szlig;e: </strong>" &amp; lenFileTextByte &amp; " Byte.<br><br>"

' --- Convert file content because HTML pages are not displayed correctly
        FileTextNew = Replace(FileTextNew, "<", "&lt;")
        FileTextNew = Replace(FileTextNew, ">", "&gt;")
        FileTextNew = Replace(FileTextNew, VbCrLf, "<br>" &amp; VbCrLf)
        FileTextNew = Replace(FileTextNew, Chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;")

' --- Output of the file content
        Response.Write FileTextNew
End Sub

Private Sub Error_Handler(intErrNumber)
' --- Determination of the transferred error code and output on the screen
        Select Case intErrNumber
                Case 10900: Response.Write ErrHeader &amp; ErrArray(0)
                Case 10901: Response.Write ErrHeader &amp; ErrArray(1)
                Case 10902: Response.Write ErrHeader &amp; ErrArray(2)
                Case 10903: Response.Write ErrHeader &amp; ErrArray(3)
                Case Else: Response.Write ErrHeader &amp; Err.Description
        End Select
        Exit Sub
End Sub

En este ejemplo, un formulario HTML simple sirve como interfaz de usuario.

<title>file upload via ASP</title>


<form method="POST" action="upload.asp" enctype="multipart/form-data" target="_new">
<input type="file" name="File" size="50"><br>
<input type="submit" value="START UPLOAD" name="Submit">


Con ASP.NET el script de carga se puede realizar de la siguiente manera:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

' Specify the path on the server to
' save the uploaded file to.
Dim savePath As String = "e:\Clientes\Sitiosweb\11\d12345678\www\UploadTest"

' Before attempting to perform operations
' on the file, verify that the FileUpload
' control contains a file.
If (FileUpload1.HasFile) Then
' Get the name of the file to upload.
Dim fileName As String = FileUpload1.FileName

' Append the name of the file to upload to the path.
savePath += fileName

' Call the SaveAs method to save the
' uploaded file to the specified path.
' This example does not perform all
' the necessary error checking.
' If a file with the same name
' already exists in the specified path,
' the uploaded file overwrites it.

' Notify the user of the name the file
' was saved under.
UploadStatusLabel.Text = "Your file was saved as " &amp; fileName

' Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload."
End If

End Sub


<html xmlns="" >
<head runat="server">
<title>FileUpload Example</title>
<form id="form1" runat="server">
<h4>File to upload:</h4>

<asp:FileUpload id="FileUpload1"

<br /><br />

<asp:Button id="UploadButton"
Text="Upload file"

<hr />

<asp:Label id="UploadStatusLabel"


En la siguiente línea todavía tienes que introducir el ruta correcta a tu presencia:

Dim savePath As String = "e:\Clientes\Sitiosweb\11\d12345678\www\UploadTest"