在我的 MVC 项目中,我有一个上传文件的表单。如果我使用 Google Chrome、Firefox 或 Opera 上传文件,我只会得到像Inventory_June_2013.xlsx
.
当我使用 IE8 上传文件时,我得到一个类似
C:\Documents and Settings\gornel\My Documents\Inventory_June_2013.xlsx
.
如何解决这个问题?
UPD
这是我的File.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace Argussite.SupplierService.Core.Domain
{
public class File : Entity
{
public const int ContentTypeLength = 100;
public const int FileNameLength = 100;
public const int StorageNameLength = 100;
protected File()
{}
public File(string name, string contentType, long fileSize)
{
Name = name;
ContentType = contentType;
FileSize = fileSize;
StorageName = Guid.NewGuid().ToString("D");
UploadTime = DateTime.Now;
}
[Required, MaxLength(FileNameLength)]
public string Name { get; set; }
[Required, MaxLength(ContentTypeLength)]
public string ContentType { get; set; }
public long FileSize { get; set; }
[Required, MaxLength(StorageNameLength)]
public string StorageName { get; set; }
public DateTime UploadTime { get; set; }
}
}
这是来自控制器的代码
public ActionResult UploadFile(Guid eventId, HttpPostedFileBase file)
{
//...
var document = new File(file.FileName, file.ContentType, file.ContentLength);
@event.FileId = document.Id;
@event.ActualDate = document.UploadTime;
Context.Files.Add(document);
file.SaveAs(GetFilePath(document.StorageName));
Register(new DocumentUploadedNotification(@event, @event.DocumentType, document, UrlBuilder));
return RedirectToAction("Details", "Suppliers", new { id = @event.SupplierId });
}
我使用类 HttpPostedFileBase 和属性 FileName。