ASP.NET – Subir un archivo al Servidor

Written by lopezatienza on 27/01/2009 – 12:43 -

Para subir a un archivo a nuestro servidor, primeramente deberemos importar la librería System.IO a nuestra página:

using System.IO;

Deberemos añadir un componente FileInput, en mi caso se llamará File1 que el nombre que se le da de manera predeterminada. He añadido también la opción de subirlo a una carpeta determinada, y si no existe, la creo:

string Path = HttpContext.Current.Server.MapPath("");
if (!System.IO.Directory.Exists(Path + @"\Nombre_Carpeta"))
{
System.IO.Directory.CreateDirectory(Path + @"\ Nombre_Carpeta");
}
string Archivo = string.Empty;
Archivo = File1.PostedFile.FileName;
Archivo = System.IO.Path.GetFileName(Archivo);
File1.PostedFile.SaveAs(Path + @"\Nombre_Carpeta\" + Archivo);


Autor: Antonio Lopez Atienza


Tags:
Posted in ASP.NET | No Comments »

Leave a Comment

 

RSS
MCC D5E