请帮忙,我对使用亚马逊网络服务是陌生的。我的asp.net mvc代码可以在本地主机上读写文件。但是在部署到亚马逊网络服务后,我得到了这样的错误 “找不到路径'C:\ inetpub \ wwwroot \ UploadedFiles \ ChurchMembers \ f3e3cdd6-8a0a-4029-ad9b-ad9d8b78c037.csv'的一部分。”我还观察到我也无法上传图像,下面是我读取文件的示例代码。我已经在网络上研究了答案,我无法真正分辨出我的代码还是需要在亚马逊服务器上设置的某种权限。你
var path = "~/UploadedFiles/ChurchMembers";
var fileName = parishId.ToString();
var fullPath = path + "/" + parishId + ".csv";
var filePath = System.IO.Path.GetFullPath(Server.MapPath(fullPath));
fileHelper.UploadFileBase(file, path, fileName, new[] { ".csv" });
public FileInfo UploadFileBase(HttpPostedFileBase UploadedFile, string ServerPath, string FileName, string[] FileExtensions)
{
if (UploadedFile != null)
{
string fileExt = Path.GetExtension(UploadedFile.FileName);
if (FileExtensions.Contains(fileExt.ToLower()))
{
try
{
string fileDirectory = HostingEnvironment.MapPath(ServerPath);
string FilePath = Path.Combine(fileDirectory, FileName + fileExt.ToLower());
//string OldPath = Path.Combine(fileDirectory, OldFileName);
FileInfo file = new FileInfo(FilePath);
if (!Directory.Exists(fileDirectory)) Directory.CreateDirectory(fileDirectory);
if (file.Exists)
{
file.Delete();
}
UploadedFile.SaveAs(FilePath);
return file;
}
catch (Exception ex)
{
return null;
}
}
else return null;
}
else return null;
}