如何解决如何在Kendo UI中上传文件?
如何将选定的文件位置路径加载到DocumentLocation文本框,我具有kendo网格,我使用编辑器模板上传文件,但是如何将文件保存到C:下潜并将文件路径复制到Document Location文本框?
在我的编辑器模板中,我有以下代码,我想要实现的目标是:首先将文件上传到C驱动器,然后将url复制到DocumentLocation文本框,以将路径保存到表/数据库中
@model Billings
<input asp-for="ID" id="ID" type="text" />
<input asp-for="DocumentLocation" id="DocumentLocation" type="text" /> // document location as C:/test.txt
<div>
<div class="demo-section k-content">
@(Html.Kendo().Upload()
.Name("files")
.Async(a => a
.Save("/Billing/Upload/Async_Save")
.Remove("/Billing/Upload/Async_Remove")
.AutoUpload(true)
)
)
</div>
</div>
我在上传控制器中使用了以下代码,看起来上传没有错误,但是没有将所选文件写入本地驱动器号C:
public partial class UploadController : Controller
{
public IHostingEnvironment HostingEnvironment { get; set; }
public UploadController(IHostingEnvironment hostingEnvironment)
{
HostingEnvironment = hostingEnvironment;
}
public async Task<ActionResult> Async_Save(IEnumerable<IFormFile> files)
{
// The Name of the Upload component is "files"
if (files != null)
{
foreach (var file in files)
{
var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"'));
// var physicalPath = Path.Combine(HostingEnvironment.WebRootPath,"App_Data",fileName);
var physicalPath = Path.Combine("C:",fileName);
// The files are not actually saved in this demo
using (var fileStream = new FileStream(physicalPath,FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
}
}
// Return an empty string to signify success
return Content("");
}
public ActionResult Async_Remove(string[] fileNames)
{
// The parameter of the Remove action must be called "fileNames"
if (fileNames != null)
{
foreach (var fullName in fileNames)
{
var fileName = Path.GetFileName(fullName);
var physicalPath = Path.Combine(HostingEnvironment.WebRootPath,fileName);
// TODO: Verify user permissions
if (System.IO.File.Exists(physicalPath))
{
// The files are not actually removed in this demo
System.IO.File.Delete(physicalPath);
}
}
}
// Return an empty string to signify success
return Content("");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。