當前位置: 首頁>>代碼示例>>C#>>正文


C# List.ToList方法代碼示例

本文整理匯總了C#中Service.List.ToList方法的典型用法代碼示例。如果您正苦於以下問題:C# List.ToList方法的具體用法?C# List.ToList怎麽用?C# List.ToList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Service.List的用法示例。


在下文中一共展示了List.ToList方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SaveUploadedFile

        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();
        }
開發者ID:salma21,項目名稱:Projet-Inventaire,代碼行數:82,代碼來源:ImportExportController.cs


注:本文中的Service.List.ToList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。