MVC4 C#将文件存储到IE11中的App_Data文件夹

时间:2016-05-16 11:16:07

标签: c# asp.net-mvc-4 csv file-upload

我正在尝试将文件存储到App_Data文件夹下的上传文件夹

            HttpPostedFileBase file = files[i];
                    string extension = Path.GetExtension(file.FileName);

                    if (Path.GetExtension(file.FileName) == ".csv")
                    {

                        if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                        {
                            string fileName = file.FileName;
                            string fileContentType = file.ContentType;
                            byte[] fileBytes = new byte[file.ContentLength];

                            NameValueCollection nvc = new NameValueCollection();
                            nvc.Add("test", "teststr");
                            nvc.Add("sample", "samplestr");

                            // store the file inside ~/App_Data/uploads folder
                            var path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/uploads"), fileName);
                            file.SaveAs(path);
    }
   }

当我在Chrome和Firefox中运行应用程序时,它工作正常,var路径返回“D:\ Sampleapp \ webportal \ SampleWeb \ App_Data \ uploads \ ShoesImportExample.csv” 哪个是对的。

但是当我在IE11中运行应用程序时,var path返回“C:\ Users \ sagar.j \ Desktop \ ShoesImportExample.csv”这是我选择文件的路径。

那么如何在IE11中获取路径“D:\ Sampleapp \ webportal \ SampleWeb \ App_Data \ uploads \ ShoesImportExample.csv”..  在此先感谢..

0 个答案:

没有答案