ファイル名をデータベースに保存するアプリケーションを開発しています。Mozilla と Chrome では FileName のみが表示されますが、IE ではファイルのフル パスが表示されます。ここで、指定されたファイル名がファイル名かファイルパスかを確認したいと思います。それを行う方法はありますか?
これが私のコードです:
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
byte[] image = null;
var file = attachments.First();
// Some browsers send file names with full path. We only care about the file name.
string filePath = Server.MapPath(General.FaxFolder + "/" + file.FileName);
file.SaveAs(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
using (BinaryReader br = new BinaryReader(fs))
{
image = br.ReadBytes((int)fs.Length);
}
TempData["Image"] = image;
System.IO.File.Delete(filePath);
return Json(new { status = "OK", imageString = Convert.ToBase64String(image) }, "text/plain");
}