Mostrando Codigo - Asp net
Upload de archivos al servidor
Efectivo script para ofrecer a nuestros visitantes subir archivos al servidor.
EXPLICACION
Este script debe estar en la misma carpeta que nuestros archivos a subir.
La carpeta debe de contener permisos de escritura.
Este codigo no lo ofrecemos ejecutable, por motivos de seguridad :-)
CODIGO
<% 'Codigo ofrecido por Tutores.org %>
<script language="VB" runat=server>
Sub DoUpload(Sender As Object, e As System.EventArgs)
Dim sPath as String
Dim sFile as String
Dim sFullPath as String
Dim sSplit() as String
Dim sPathsubir as String
sPath = Server.MapPath(".")
If Right(sPath, 1) <> "" then
sPathsubir = sPath 'CArpeta a subir
sPath = sPath & ""
Else
sPathsubir = Left(sPath, Len(sPath) - 1)
End If
sFile = txtUpload.PostedFile.FileName
sSplit = Split(sFile, "")
sFile = sSplit(Ubound(sSplit))
sFullPath = sPath & sFile
Try
txtUpload.PostedFile.SaveAs(sFullPath)
lblResults.Text = "El archivo " & sFile & " to " & sPathsubir & " subio correctamente"
Catch Ex as Exception
lblResults.Text = "El archivo " & sFile & " to " & sPathsubir & " No pudo subirse al servidor por la siguiente razon: " & Ex.Message
Finally
lblResults.Font.Bold = True
lblResults.Visible = true
End Try
End Sub
</script>
<html>
<body>
<form enctype="multipart/form-data" runat=server>
<FONT face = +1><B> </b></FONT>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#990000"><font face = +1><b><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Selecciona un archivo
a subir:</font></b></font> <font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="file" type=file id="txtUpload" runat=server>
</font> </td>
</tr>
</table>
<P align = CENTER>
<asp:button id=btnUpload Text="Upload File" OnClick="DoUpload" runat=server/>
<hr noshade>
<asp:label id="lblResults" Visible=false runat=server/>
</form>
</body>
</html>
ENLACE AL CODIGO
Si quieres enlazar desde tu pagina a este codigo<!-- Inicio enlace Tutores.org -->
<a title="Tutores.org - Upload de archivos al servidor" href="http://www.tutores.org/codigo/549/" target="_blank">Upload de archivos al servidor</a>
<!-- Final enlace Tutores.org -->
<a title="Tutores.org - Upload de archivos al servidor" href="http://www.tutores.org/codigo/549/" target="_blank">Upload de archivos al servidor</a>
<!-- Final enlace Tutores.org -->
COMENTARIOS












