I would like to know how I could upload a flat file (excel) and using asp.net c # a web form to load it and save the data in sql, here I upload the file, I keep it in a local folder and now what I need is to save the content of the excel file in SQL Server in a table
protected void btn_guardar_Archivo_Click(object sender, EventArgs e)
{
try
{
if (generarError(FUpL_Arch, "Debe seleccionar el archivo que va adjuntar", (!FUpL_Arch.HasFile))) { return; }
else
{
if (Request.Files.Count > 0)
{
int vLenght = 0;
string Ruta = Server.MapPath("~/Archivos/DOCUMENTOS_ADJUNTOS/PRUEBAS/" + "Prueba_" + IdUsuario.ToString());
foreach (string item in Request.Files)
{
HttpPostedFile ofile = Request.Files[item];
if (ofile.ContentLength > 0)
{
if (!System.IO.Directory.Exists(Ruta))
{
System.IO.Directory.CreateDirectory(Ruta);
}
string NombreArch = "Prueba_" + IdUsuario.ToString() + DateTime.Now.ToShortDateString();
Ruta = System.IO.Path.Combine(Ruta, NombreArch + System.IO.Path.GetExtension(ofile.FileName));
ofile.SaveAs(Ruta);
vLenght += ofile.ContentLength;
}
}
MostrarMensaje("El Archivo se ha Subido Correctamente");
}
}
}
catch (Exception ex)
{
ControlarExcepcion(ex);
}
}