如何在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 (将#修改为@)