本文整理汇总了C#中IFormFile.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.SaveAs方法的具体用法?C# IFormFile.SaveAs怎么用?C# IFormFile.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormFile
的用法示例。
在下文中一共展示了IFormFile.SaveAs方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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信息导入成功";
});
}
示例3: ImportTeaching
public IActionResult ImportTeaching(IFormFile file)
{
string root = @"Temp/teachingfile/";
string phyPayh = evn.MapPath(root);
if (file != null)
{
var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
var originalName = parsedContentDisposition.FileName.Replace("\"", "");
string ext = Path.GetExtension(originalName);
file.SaveAs(phyPayh + DateHelper.GetTimeStamp()+ext);
}
else
{
ModelState.AddModelError("", "没有选择文件");
return View();
}
return RedirectToAction("Index");
}
示例4: Post
public void Post(int id, IFormFile file)
{
if (file.Length > 0)
{
var uploads = "photos";
var uploadsAbsPath = Path.Combine(env.WebRootPath, uploads);
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var relFileName = Path.Combine(uploads, fileName);
var hero = new Hero
{
Photo = relFileName
};
this.service.Update(id, hero);
file.SaveAs(Path.Combine(uploadsAbsPath, fileName));
}
}
示例5: Create
public IActionResult Create(IFormFile croppedImage1, string shortDesc, string longDesc, decimal originalPrice, decimal discountPrice)
{
//Save image
var uploads = Path.Combine(_environment.WebRootPath, "Uploads");
if (croppedImage1.Length > 0)
{
var prizeImageId = Guid.NewGuid().ToString();
var fileName = string.Format("{0}.jpg", prizeImageId);
croppedImage1.SaveAs(Path.Combine(uploads, fileName));
ImageResizer.ImageJob img1 = new ImageResizer.ImageJob(Path.Combine(uploads, fileName), Path.Combine(uploads, "Prizes", "400", fileName),
new ImageResizer.Instructions("maxheight=400;&scale=both;format=jpg;mode=max"));
img1.Build();
ImageResizer.ImageJob img2 = new ImageResizer.ImageJob(Path.Combine(uploads, fileName), Path.Combine(uploads, "Prizes", "600", fileName),
new ImageResizer.Instructions("maxheight=600;&scale=both;format=jpg;mode=max"));
img2.Build();
Prize newPrize = new Prize();
newPrize.PrizeImage = prizeImageId;
newPrize.ShortDesc = shortDesc;
newPrize.LongDesc = longDesc;
newPrize.OriginalPrice = originalPrice;
newPrize.DiscountPrice = discountPrice;
newPrize.ShopId = 2;
newPrize.Status = (int)EnumHelper.PrizeStatus.InProduction;
if (ModelState.IsValid)
{
_context.Prize.Add(newPrize);
_context.SaveChanges();
}
}
return View();
}
示例6: getWines
public async Task<List<string>> getWines(IFormFile file)
{
var fileName=ContentDispositionHeaderValue.Parse(file.ContentDisposition)
.FileName
.Trim('"');
var filePath=_hosting.WebRootPath+"\\Documents\\"+DateTime.Now.ToString("yyyyddMHHmmss")+fileName;
file.SaveAs(filePath);
List<string> platos=new List<string>();
AspriseOCR.SetUp();
client=new AspriseOCR();
client.StartEngine("eng",AspriseOCR.SPEED_SLOW);
string text=client.Recognize(filePath, -1,-1,-1,-1,-1,AspriseOCR.RECOGNIZE_TYPE_ALL, AspriseOCR.OUTPUT_FORMAT_PLAINTEXT);
string[] list=text.Split(new char[] {' '});
List<string> selected=await plato.LookFor(list);
return selected;
}
示例7: UploadFile
public ActionResult UploadFile(IFormFile file)
{
var files = "";
file.SaveAs("C://excel.xlsx");
//var uploadStatus = "";
//if (files != null)
//{
// try
// {
// string uploadLocation = "";
// Users objUser = ((Users)(Session["CurrentUser"]));
// var companyId = objUser.CompanyId;
// //Logo Store Location
// //Virtual Directory
// var logoPathWillbe = @"~/UploadAttendance/Attendance/" + companyId;
// //Creating Directory If Not exist
// uploadLocation = Utility.GetUploadPath(logoPathWillbe);
// foreach (var file in files)
// {
// var fileName = Path.GetFileName(file.FileName);
// var physicalPath = Path.Combine(Server.MapPath(logoPathWillbe), DateTime.Now.Ticks + fileName);
// file.SaveAs(physicalPath);
// Session["UploadAttendance"] = physicalPath;
// }
// }
// catch (Exception ex)
// {
// Session["UploadAttendance"] = null;
// uploadStatus = ex.Message;
// }
//}
// Return an empty string to signify success
return Content("");
}
示例8: CreateDocument
public IActionResult CreateDocument(long id, string filename,string type, IFormFile file)
{
var user = DB.Users
.Where(x => x.Id == id)
.SingleOrDefault();
if (type == "文档")
{
file.SaveAs(".\\wwwroot\\uploads\\" + user.UserName + "\\document\\" + filename + ".docx");
var fileinfo = new Models.FileInfo
{
Title = filename,
CreateTime = DateTime.Now,
Path = user.UserName + "\\document\\" + filename + ".docx",
FType = FType.文档,
StudentId = DB.Students.Where(x => x.UserId == user.Id).SingleOrDefault().Id,
};
DB.FinleInfos.Add(fileinfo);
DB.SaveChanges();
var log = DB.Logs.Add(new Log
{
Roles = Roles.学生,
Operation = Operation.上传文件,
Time = DateTime.Now,
Number = fileinfo.Id,
UserId = User.Current.Id,
});
}
else if (type == "论文")
{
file.SaveAs(".\\wwwroot\\uploads\\" + user.UserName + "\\thesis\\" + filename + ".docx");
var fileinfo = new Models.FileInfo
{
Title = filename,
CreateTime = DateTime.Now,
Path = user.UserName + "\\thesis\\" + filename + ".docx",
FType = FType.论文,
StudentId = DB.Students.Where(x => x.UserId == user.Id).SingleOrDefault().Id,
};
DB.FinleInfos.Add(fileinfo);
DB.SaveChanges();
var log = DB.Logs.Add(new Log
{
Roles = Roles.学生,
Operation = Operation.上传文件,
Time = DateTime.Now,
Number = fileinfo.Id,
UserId = User.Current.Id,
});
}
else if (type == "外文翻译")
{
file.SaveAs(".\\wwwroot\\uploads\\" + user.UserName + "\\english\\" + filename + ".docx");
var fileinfo = new Models.FileInfo
{
Title = filename,
CreateTime = DateTime.Now,
Path = user.UserName + "\\english\\" + filename + ".docx",
FType = FType.外文翻译,
StudentId = DB.Students.Where(x => x.UserId == user.Id).SingleOrDefault().Id,
};
DB.FinleInfos.Add(fileinfo);
DB.SaveChanges();
var log = DB.Logs.Add(new Log
{
Roles = Roles.学生,
Operation = Operation.上传文件,
Time = DateTime.Now,
Number = fileinfo.Id,
UserId = User.Current.Id,
});
}
else
{
file.SaveAs(".\\wwwroot\\uploads\\" + user.UserName + "\\report\\" + filename + ".docx");
var fileinfo = new Models.FileInfo
{
Title = filename,
CreateTime = DateTime.Now,
Path = user.UserName + "\\report\\" + filename + ".docx",
FType = FType.报告,
StudentId = DB.Students.Where(x => x.UserId == user.Id).SingleOrDefault().Id,
};
DB.FinleInfos.Add(fileinfo);
DB.SaveChanges();
var log = DB.Logs.Add(new Log
{
Roles = Roles.学生,
Operation = Operation.上传文件,
Time = DateTime.Now,
Number = fileinfo.Id,
UserId = User.Current.Id,
});
}
DB.SaveChanges();
return RedirectToAction("Document", "Home");
}
示例9: CreateSourceCode
public IActionResult CreateSourceCode(long id,string filename,IFormFile file)
{
var user = DB.Users
.Where(x => x.Id == id)
.SingleOrDefault();
file.SaveAs(".\\wwwroot\\uploads\\" + user.UserName + "\\sourcecode\\" + filename + ".zip");
var fileinfo = new Models.FileInfo
{
Title = filename,
CreateTime = DateTime.Now,
Path = user.UserName + "\\sourcecode\\" + filename + ".zip",
FType = FType.源代码,
StudentId = DB.Students.Where(x => x.UserId == user.Id).SingleOrDefault().Id,
};
DB.FinleInfos.Add(fileinfo);
DB.SaveChanges();
var log = DB.Logs.Add(new Log
{
Roles = Roles.学生,
Operation = Operation.上传文件,
Time = DateTime.Now,
Number = fileinfo.Id,
UserId = User.Current.Id,
});
DB.SaveChanges();
return RedirectToAction("SourceCode", "Home");
}
示例10: 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");
}
示例11: 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);
}
示例12: NewJudge
public string NewJudge(long id, IFormFile user, IFormFile problem, string nuget)
{
var identifier = id;
var directory = Path.GetTempPath() + [email protected]"/vec/{identifier}/";
if (OS.Current == OSType.Windows)
directory = directory.Replace('/', '\\');
else
directory = directory.Replace('\\', '/');
directory = directory.Replace(@"\\", @"\");
directory = directory.Replace(@"//", @"/");
Console.WriteLine("工作路径 "+ Path.GetTempPath() + [email protected]"/vec/{identifier}/");
if (Directory.Exists(directory))
Directory.Delete(directory.TrimEnd('\\').TrimEnd('/'), true);
Directory.CreateDirectory(directory);
user.SaveAs(directory + [email protected]"/{identifier}.zip");
Console.WriteLine("用户程序保存成功 " + directory + [email protected]"/{identifier}.zip");
Unzip.ExtractAll(directory + [email protected]"/{identifier}.zip", directory + "/user/", true);
Console.WriteLine("用户程序解压成功 " + directory + "/user");
var tempDirectory = Path.GetTempPath() + "/vec/";
if (!Directory.Exists(tempDirectory))
Directory.CreateDirectory(tempDirectory);
if (!Directory.Exists(tempDirectory + identifier))
Directory.CreateDirectory(tempDirectory + identifier);
problem.SaveAs(tempDirectory + identifier + "/" + identifier + ".zip");
Console.WriteLine("测试程序保存成功 " + tempDirectory + identifier + "/" + identifier + ".zip");
Unzip.ExtractAll(tempDirectory + identifier + "/" + identifier + ".zip", tempDirectory + identifier + "/experiment/", true);
Console.WriteLine("测试程序解压成功 " + tempDirectory + identifier + "/experiment/");
CopyDirectory(FindRoot(tempDirectory + identifier + "/experiment"), Configuration["Pool"] + "/" + identifier);
CopyDirectory(FindProject(directory + "/user"), Configuration["Pool"] + "/" + identifier + "/src/web");
Console.WriteLine($"生成评测目录 {Configuration["Pool"] + "/" + identifier}");
if (nuget == null) nuget = "";
System.IO.File.WriteAllText(Configuration["Pool"] + "/" + identifier + "/Nuget.config", GenerateNuGetConfig(nuget.Split('\n')));
Console.WriteLine($"生成NuGet.config {Configuration["Pool"] + "/" + identifier + "/Nuget.config"}");
Runner.WaitingTasks.Enqueue(new CITask(identifier.ToString(), Configuration["Pool"] + "/" + identifier, Runner.MaxTimeLimit));
return "ok";
}