public ActionResult SaveUploadedFile(string id) { bool isSavedSuccessfully = true; string fName = ""; string fileName1 = ""; string fileExtension = ""; string pathFile = ""; DataTable ds = new DataTable(); try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; fName = file.FileName; fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (file != null && file.ContentLength > 0 && (file.FileName.EndsWith("xls") || file.FileName.EndsWith("xlsx"))) { var originalDirectory = new DirectoryInfo(string.Format("{0}Fichiers", Server.MapPath(@"\"))); string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "Exels"); fileName1 = Path.GetFileName(file.FileName); bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) System.IO.Directory.CreateDirectory(pathString); pathFile = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(pathFile); } else { ViewBag.Error = "Selectionner un fichier Excel SVP !!!"; return View("Index"); } } } catch (Exception ex) { isSavedSuccessfully = false; } if (isSavedSuccessfully) { List<Bien> list = new List<Bien>(); ds = ExcelParser.Instance.ExcelParserToDataTable(pathFile, null); foreach (DataRow row in ds.Rows) { Bien catalogue = new Bien(); //catalogue.Code_a_barre = Convert.ToInt32(row["Code matériel "]); catalogue.Num_Serie = row["N° de série "].ToString(); ///var i = db.FindCategorie_materielByNom(row["Catégorie "].ToString()); //catalogue.Categorie_materiel = Convert.ToString(i.Id_Categorie_materiel); catalogue.Modele = row["Modèle "].ToString(); catalogue.Marque = row["Marque "].ToString(); catalogue.Etat = row["Statut "].ToString(); //catalogue.Fin_garantie = Convert.ToDateTime(row["Fin de garantie "]); catalogue.Id_etage = Convert.ToInt32(row["Localisation (dernier niveau) "]); catalogue.idBatiment = Convert.ToInt32(row["Entité (dernier niveau) "]); //catalogue.Date_d_inventaire = Convert.ToDateTime(row["Date inventaire "]); catalogue.Date_d_installation = Convert.ToDateTime(row["Date d'installation "]); catalogue.idBatiment = Convert.ToInt32(row["Localisation (complet) "]); //catalogue.id_direction = Convert.ToInt32(row["Entité (complet) "]); //catalogue.Code_materiel.ToString() = Code; list.Add(catalogue); BissInventaireEntities.Instance.Bien.Add(catalogue); BissInventaireEntities.Instance.SaveChanges(); } Session["Tesst"] = list.ToList(); return View("Create1"); } return HttpNotFound(); }