是否有可能转换HttpPostedFileBase to HttpPostedFile,我试图搜索,所以问题,我只能找到正好相反的情况HttpPostedFile到HttpPostedFileBase。
试读:files
他说:“在某些情况下,我们需要将HttpPostedFileBase转换为HttpPostedFile,我们可以使用HttpPostedFileWrapper实现这一点。”
请不要告诉我要使用HttpPostedFileBase,因为我使用的是DevExpress框架UploadedFile类,它只接受构造函数中的HttpPostedFile。
我试过这样做,但是不知道我还应该写什么HttpPostedFile
HttpFileCollectionBase files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
var file = files.Get(i);
}谢谢您的时间和帮助提前。
发布于 2016-03-22 11:01:07
我的问题的解决办法如下:
List<UploadedFile> uploadedFiles = new List<UploadedFile>();
var files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
var file = files.Get(i);
var constructorInfo = typeof(HttpPostedFile).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
var obj = (HttpPostedFile)constructorInfo
.Invoke(new object[] { file.FileName, file.ContentType, file.InputStream });
uploadedFiles.Add(new UploadedFile(obj));
}发布于 2016-03-21 14:36:29
这篇文章似乎是在做你想要的。您必须获取HttpPostedFileBase中的字节数组,但它应该能做到这一点:
https://stackoverflow.com/questions/36133385
复制相似问题