我正在使用api服务器,数据库服务器和Web服务器不同的应用程序。我们创建一个服务器来存储文件并创建虚拟目录来访问所有文件。但我的问题是如何存储文件这个位置。我的网络位置是 \ 10.0.0.51 \ CB-Clients 我如何在这个位置存储文件。我的代码是
string _path =Path.Combine("\\10.0.0.51\CB-Clients\", "abc.png");
FileStream newFile = new FileStream(_path, FileMode.Create);
newFile.Write(userWiseDocumentStorage.DocImageByte, 0, userWiseDocumentStorage.DocImageByte.Length);
newFile.Close();
但问题是文件没有上传此位置
答案 0 :(得分:0)
按照以下步骤尝试.... 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();
}