I have a web interface where users can choose one of many files from local computer and upload them to a central location, in this case Azure Blob Storage
. I have a check in my C#
code to validate that the filename ending is .bin
. The receiving method in C#
takes an array of HttpPostedFileBase
.
I want to allow users to choose a zipfile instead. In my C#
code, I iterate through the content of the zipfile and check each filename to verify that the ending is .bin
.
However, when I iterate through the zipfile, the ContentLength
of the HttpPostedFileBase
object becomes 0
(zero) and when I later on upload the zipfile to Azure
, it is empty.
How can I make a check for filename endings without manipulating the zipfile?
- I have tried to
DeepCopy
a single object ofHttpPostedFileBase
but it is not serializable. - I've tried to make a copy of the
array
but nothing works. It seems that everything is reference and not value. Some example of my code as follows. Yes, I tried the lines individually.
private static bool CanUploadBatchOfFiles(HttpPostedFileBase[] files)
{
var filesCopy = new HttpPostedFileBase[files.Length];
// Neither of these lines works
Array.Copy(files, 0, filesCopy, 0, files.Length);
Array.Copy(files, filesCopy, files.Length);
files.CopyTo(filesCopy, 0);
}
This is how I iterate through the zipfile
foreach (var file in filesCopy)
{
if (file.FileName.EndsWith(".zip"))
{
using (ZipArchive zipFile = new ZipArchive(file.InputStream))
{
foreach (ZipArchiveEntry entry in zipFile.Entries)
{
if (entry.Name.EndsWith(".bin"))
{
// Some code left out
}
}
}
}
}