ASP.NET MVC5文件上传问题



我正在工作一个API服务器,DB服务器和Web服务器的应用程序。我们创建一个服务器来存储文件并创建虚拟目录以访问所有文件。但是我的问题是如何存储此位置。我的网络位置是 10.0.0.51 CB-CLIENTS 如何将文件存储在此位置。我的代码是

string _path =Path.Combine("\10.0.0.51CB-Clients", "abc.png");
 FileStream newFile = new FileStream(_path, FileMode.Create);
newFile.Write(userWiseDocumentStorage.DocImageByte, 0, userWiseDocumentStorage.DocImageByte.Length);
newFile.Close();

但问题是文件没有上传此位置

遵循以下步骤并尝试。1.在appsettings中添加webconfig文件中的位置,例如

  <appSettings>
        <add key="DocumentationLocation" value="D:CB-Clients" />
  </appSettings>

2.然后在控制器操作中尝试此代码:

     public ActionResult FileSave(HttpPostedFileBase file)
                {
                    string _FileName = null;
                    string _path = null;                   
                    _FileName = Path.GetFileName(file.FileName);
                    string ext = Path.GetExtension(_FileName);
                    string file1 = _FileName.Replace(" ", "");
                    if (ext.ToLower() == ".pdf" || ext.ToLower() == ".doc" || ext.ToLower() == ".jpg" || ext.ToLower() == ".docx" || ext.ToLower() == ".xls" || ext.ToLower() == ".xlsx" || ext.ToLower() == ".jpeg" || ext.ToLower() == ".png")
                    {
                        string location = (System.Configuration.ConfigurationSettings.AppSettings["DocumentationLocation"]);
                        _path = Path.Combine(location, file1);
                        if (System.IO.File.Exists(_path))
                        {
                            System.IO.File.Delete(_path);
                            file.SaveAs(_path);
                        }
                        else
                        {
                            file.SaveAs(_path);
                        }
                    }
                    return View();
                }

最新更新