我有一个多文件上传的表单。 (您可以在同一个文件控件中选择多个文件
我必须将这些文件上传到API
如果我没有多个,但只有一个文件上载,我可以
byte[] filedata = FileUploadControl.FileBytes;
String filestring = Convert.ToBase64String(filedata);
如果有多个fileupload,我可以使用它来迭代文件:
HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile uploadfile = fileCollection[i];
if (uploadfile.ContentLength > 0)
{
Int32 ContentLength = uploadfile.ContentLength;
String ContentType = uploadfile.ContentType;
string filename = uploadfile.FileName;
}
}
但我没有uploadfile.FileBytes
如何将文件内容变为字符串?
答案 0 :(得分:0)
我让它像这样工作:
HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile uploadfile = fileCollection[i];
if (uploadfile.ContentLength > 0)
{
...
MemoryStream ms = new MemoryStream(uploadfile.ContentLength);
uploadfile.InputStream.CopyTo(ms);
String filestring = Convert.ToBase64String(ms.ToArray());
...
}
}