当前位置: 首页>>代码示例>>C#>>正文


C# IFormFile.GetFileName方法代码示例

本文整理汇总了C#中IFormFile.GetFileName方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.GetFileName方法的具体用法?C# IFormFile.GetFileName怎么用?C# IFormFile.GetFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFormFile的用法示例。


在下文中一共展示了IFormFile.GetFileName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: F

 public IActionResult F(IFormFile file, string city)
 {
     var fname = Guid.NewGuid().ToString().Replace("-", "") + System.IO.Path.GetExtension(file.GetFileName());
     var path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fname);
     file.SaveAs(path);
     string connStr;
     if (System.IO.Path.GetExtension(path) == ".xls")
         connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
     else
         connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";
     using (var conn = new OleDbConnection(connStr))
     {
         conn.Open();
         var schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
         var rows = schemaTable.Rows;
         foreach (System.Data.DataRow r in rows)
         {
             if (r["TABLE_NAME"].ToString() == "_xlnm#_FilterDatabase")
                 continue;
             var cmd = new OleDbCommand($"select * from [{r["TABLE_NAME"].ToString()}]", conn);
             var reader = cmd.ExecuteReader();
             var flag = reader.Read();
             flag = reader.Read();
             flag = reader.Read();
             if (flag)
             {
                 while (reader.Read())
                 {
                     try
                     {
                         var text = new List<string>();
                         for (var i = 0; i < HeaderOfE.Count(); i++)
                             text.Add(reader[i].ToString());
                         DB.Forms.Add(new Models.Form
                         {
                             City = city,
                             Content = JsonConvert.SerializeObject(text),
                             Time = DateTime.Now,
                             Type = Models.FormType.疑难站点库
                         });
                     }
                     catch (Exception e)
                     {
                         Console.WriteLine(e.ToString());
                     }
                 }
                 DB.SaveChanges();
             }
         }
     }
     return RedirectToAction("F", "Form", null);
 }
开发者ID:CodeCombLLC,项目名称:ChinaTower,代码行数:52,代码来源:FormController.cs

示例2: Upload

        public IActionResult Upload(IFormFile file)
        {
            if (!User.IsSignedIn())
                return Json(new
                {
                    code = 403,
                    msg = "Forbidden"
                });

            if (file == null)
                return Json(new
                {
                    code = 400,
                    msg = "File not found"
                });

            var _file = new Blob();
            _file.FileName = file.GetFileName();
            _file.Time = DateTime.Now;
            _file.Id = Guid.NewGuid();
            _file.ContentLength = file.Length;
            _file.ContentType = file.ContentType;
            _file.File = file.ReadAllBytes();
            DB.Blobs.Add(_file);
            DB.SaveChanges();
            return Json(new
            {
                code = 200,
                fileId = _file.Id.ToString()
            });
        }
开发者ID:Jeffiy,项目名称:vnextcn.org,代码行数:31,代码来源:FileController.cs

示例3: Import

 public IActionResult Import(IFormFile file)
 {
     var src = new List<RxLevPoint>();
     var fname = Guid.NewGuid().ToString().Replace("-", "") + System.IO.Path.GetExtension(file.GetFileName());
     var path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fname);
     file.SaveAs(path);
     string connStr;
     if (System.IO.Path.GetExtension(path) == ".xls")
         connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
     else
         connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";
     using (var conn = new OleDbConnection(connStr))
     {
         conn.Open();
         var schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
         var rows = schemaTable.Rows;
         foreach (System.Data.DataRow r in rows)
         {
             if (r["TABLE_NAME"].ToString() == "_xlnm#_FilterDatabase")
                 continue;
             var cmd = new OleDbCommand($"select * from [{r["TABLE_NAME"].ToString()}]", conn);
             var reader = cmd.ExecuteReader();
             var flag = reader.Read();
             var cities = User.Claims.Where(x => x.Type == "有权限访问地市数据").Select(x => x.Value).ToList();
             if (flag)
             {
                 while (reader.Read())
                 {
                     try
                     {
                         src.Add(new RxLevPoint
                         {
                             Lon = Convert.ToDouble(reader[0]),
                             Lat = Convert.ToDouble(reader[1]),
                             Signal = Convert.ToInt32(reader[2])
                         });
                     }
                     catch
                     {
                     }
                 }
             }
         }
     }
     var ret = Algorithms.p2l.Handle(src);
     DB.RxLevLines.AddRange(ret);
     DB.SaveChanges();
     return Prompt(x =>
     {
         x.Title = "导入成功";
         x.Details = "RxLev信息导入成功";
     });
 }
开发者ID:CodeCombLLC,项目名称:ChinaTower,代码行数:53,代码来源:PavementController.cs

示例4: EditAvatar

 public async Task<IActionResult> EditAvatar(long id,IFormFile avatar,User Model)
 {
     var user = DB.Users
         .Include(x=>x.Avatar)
         .Where(x => x.Id == id)
         .SingleOrDefault();
     if (avatar != null)
     {
         try
         {
             DB.Files.Remove(DB.Files.Single(x => x.Id == user.AvatarId));
         }
         catch { }
         var file = new CodeComb.AspNet.Upload.Models.File
         {
             Bytes = await avatar.ReadAllBytesAsync(),
             ContentLength = avatar.Length,
             ContentType = avatar.ContentType,
             FileName = avatar.GetFileName(),
             Time = DateTime.Now
         };
         DB.Files.Add(file);
         user.AvatarId = file.Id;
     }
     DB.SaveChanges();
     return RedirectToAction("Center", "Home");
 }
开发者ID:Cream2015,项目名称:EMWeb,代码行数:27,代码来源:HomeController.cs

示例5: Import

 public IActionResult Import(IFormFile file)
 {
     var env = Resolver.GetService<IApplicationEnvironment>();
     if (!Directory.Exists(env.ApplicationBasePath + "/tmp"))
         Directory.CreateDirectory(env.ApplicationBasePath + "/tmp");
     var fname = env.ApplicationBasePath + "/tmp/" + Guid.NewGuid() + Path.GetExtension(file.GetFileName());
     file.SaveAs(fname);
     string connStr;
     if (Path.GetExtension(fname) == ".xls")
         connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fname + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
     else
         connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fname + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";
     Task.Factory.StartNew(() =>
     {
         long i = 0;
         var conn = new OleDbConnection(connStr);
         conn.Open();
         var cmd = new OleDbCommand("select * from [Sheet1$]", conn);
         using (var reader = cmd.ExecuteReader())
         {
             var flag = reader.Read();
             if (flag)
             {
                 while (reader.Read())
                 {
                     i++;
                     if (i % 1000 == 0)
                     {
                         Console.WriteLine("已经导入" + i +"条记录。");
                     }
                     try
                     {
                         Status status;
                         if (reader[1].ToString() == "欠停(单向)")
                             status = Status.单向欠停;
                         else if (reader[1].ToString() == "欠停(双向)")
                             status = Status.双向欠停;
                         else
                             status = (Status)Enum.Parse(typeof(Status), reader[1].ToString());
                         if (DB.CustomerDetails.Any(x => x.Account == reader[0].ToString()))
                         {
                             var detail = DB.CustomerDetails.Where(x => x.Account == reader[0].ToString()).Single();
                             detail.Status = status;
                             detail.CustomerName = reader[2].ToString();
                             detail.ContractorName = reader[3].ToString();
                             detail.ContractorStruct = reader[4].ToString();
                             detail.CurrentMonthBill = reader[5] == DBNull.Value ? 0 : Convert.ToDouble(reader[5]);
                             detail.AgentFee = reader[7] == DBNull.Value ? 0 : Convert.ToDouble(reader[7]);
                             detail.Commission = reader[8] == DBNull.Value ? 0 : Convert.ToDouble(reader[8]);
                             detail.Arrearage = reader[9] == DBNull.Value ? 0 : Convert.ToDouble(reader[9]);
                             detail.ImplementAddress = reader[10].ToString();
                             detail.StandardAddress = reader[11].ToString();
                             detail.Set = reader[12].ToString();
                         }
                         else
                         {
                             DB.CustomerDetails.Add(new CustomerDetail
                             {
                                 Account = reader[0].ToString(),
                                 Status = status,
                                 CustomerName = reader[2].ToString(),
                                 ContractorName = reader[3].ToString(),
                                 ContractorStruct = reader[4].ToString(),
                                 CurrentMonthBill = reader[5] == DBNull.Value ? 0 : Convert.ToDouble(reader[5]),
                                 AgentFee = reader[7] == DBNull.Value ? 0 : Convert.ToDouble(reader[7]),
                                 Commission = reader[8] == DBNull.Value ? 0 : Convert.ToDouble(reader[8]),
                                 Arrearage = reader[9] == DBNull.Value ? 0 : Convert.ToDouble(reader[9]),
                                 ImplementAddress = reader[10].ToString(),
                                 StandardAddress = reader[11].ToString(),
                                 Set = reader[12].ToString()
                             });
                         }
                     }
                     catch
                     {
                         Console.WriteLine("Error #" + i);
                     }
                 }
             }
         }
         DB.SaveChanges();
         conn.Close();
     });
     return RedirectToAction("Importing", "Customer");
 }
开发者ID:Kagamine,项目名称:ChinaTelecomDaoLi,代码行数:85,代码来源:CustomerController.cs

示例6: G

        public IActionResult G(IFormFile file, string city)
        {
            var fname = Guid.NewGuid().ToString().Replace("-", "") + System.IO.Path.GetExtension(file.GetFileName());
            var path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fname);
            file.SaveAs(path);
            string connStr;
            if (System.IO.Path.GetExtension(path) == ".xls")
                connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
            else
                connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";
            using (var conn = new OleDbConnection(connStr))
            {
                conn.Open();
                var schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                var rows = schemaTable.Rows;
                foreach (DataRow r in rows)
                {
                    if (r["TABLE_NAME"].ToString() == "_xlnm#_FilterDatabase")
                        continue;
                    var cmd = new OleDbCommand($"select * from [{r["TABLE_NAME"].ToString()}]", conn);
                    var adpt = new OleDbDataAdapter(cmd);
                    var dt = new DataTable();
                    adpt.Fill(dt);
                    var text = new List<string>();
                    text.Add(dt.Rows[1][3].ToString());
                    text.Add(dt.Rows[1][8].ToString());
                    text.Add(dt.Rows[2][3].ToString());
                    text.Add(dt.Rows[2][8].ToString());
                    text.Add(dt.Rows[3][3].ToString());
                    text.Add(dt.Rows[3][8].ToString());
                    text.Add(dt.Rows[4][3].ToString());
                    text.Add(dt.Rows[4][8].ToString());
                    text.Add(dt.Rows[5][3].ToString());
                    text.Add(dt.Rows[5][8].ToString());
                    text.Add(dt.Rows[6][3].ToString());
                    text.Add(dt.Rows[6][8].ToString());
                    text.Add(dt.Rows[7][3].ToString());
                    text.Add(dt.Rows[7][8].ToString());
                    text.Add(dt.Rows[8][3].ToString());
                    text.Add(dt.Rows[8][8].ToString());
                    text.Add(dt.Rows[9][3].ToString());
                    text.Add(dt.Rows[9][8].ToString());
                    text.Add(dt.Rows[10][3].ToString());
                    text.Add(dt.Rows[10][8].ToString());
                    var form = new Models.Form
                    {
                        City = city,
                        Content = JsonConvert.SerializeObject(text),
                        Time = DateTime.Now,
                        Type = Models.FormType.疑难站址档案
                    };
                    DB.Forms.Add(form);

                    for (var i = 11; i + 3 < dt.Rows.Count; i += 3)
                    {
                        var text2 = new List<string>();
                        text2.Add(dt.Rows[i][3].ToString());
                        text2.Add(dt.Rows[i][8].ToString());
                        text2.Add(dt.Rows[i + 1][3].ToString());
                        text2.Add(dt.Rows[i + 1][8].ToString());
                        text2.Add(dt.Rows[i + 2][3].ToString());
                        DB.Forms.Add(new Models.Form
                        {
                            City = city,
                            Time = DateTime.Now,
                            Type = Models.FormType.疑难站址档案2,
                            ParentId = form.Id,
                            Content = JsonConvert.SerializeObject(text2),
                        });
                    }

                    DB.SaveChanges();
                }
            }
            return RedirectToAction("G", "Form", null);
        }
开发者ID:CodeCombLLC,项目名称:ChinaTower,代码行数:76,代码来源:FormController.cs


注:本文中的IFormFile.GetFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。