Asp.net mvc 4 Don';无法在IE8(asp.net mvc)中获得正确的上载文件名
在我的MVC项目中,我有一个上传文件的表单。如果我使用Google Chrome、Firefox或Opera上传文件,我只会得到文件名,比如Asp.net mvc 4 Don';无法在IE8(asp.net mvc)中获得正确的上载文件名,asp.net-mvc-4,Asp.net Mvc 4,在我的MVC项目中,我有一个上传文件的表单。如果我使用Google Chrome、Firefox或Opera上传文件,我只会得到文件名,比如Inventory\u June\u 2013.xlsx 当我使用IE8上传文件时,我会得到一个文件名,比如 C:\Documents and Settings\gornel\My Documents\Inventory\u June\u 2013.xlsx 如何解决这个问题 UPD 这是我的文件.cs using System; using System.
Inventory\u June\u 2013.xlsx
当我使用IE8上传文件时,我会得到一个文件名,比如
C:\Documents and Settings\gornel\My Documents\Inventory\u June\u 2013.xlsx
如何解决这个问题
UPD这是我的文件.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。众所周知,IE返回完整路径,而其他浏览器只提供文件名。不幸的是,这种情况必须由您自己处理,asp.net对此无能为力
您可以使用method只获取文件名部分。您可以显示处理上传文件的代码吗?我更新了我的问题。因此,所有代码中的哪个变量的值错误?请删除不必要的代码,这对问题没有价值。现在更清楚了,在这种情况下,您的问题在中得到了回答。我使用以下代码
var document=new File(File.FileName,File.ContentType,File.ContentLength)代码>我应该如何更改?请使用此代码更新您的问题。并显示什么文件
isI更新了我的问题。