Firstly, as in the other question link to, having a method that requires a HttpPostedFileBase
as an input, and then requires you to send a file not automatically transferred as a HttpPostedFileBase
, suggests you need to refactor the method. In the example by Pommy, perhaps an input of Stream
would be more appropriate?
Now, if you absolutely must have an instance of HttpPostedFileBase
, here's what you're up against. The class is abstract, so you're never going to construct it directly. Instead you'll need to construct an inheriting class. Within the standard libraries, HttpPostedFileWrapper
inherits, and takes HttpPostedFile
as a constructor input.
But here's the rub, the constructor for HttpPostedFile
is internal, so outside of the System.Web library, you're not constructing an instance directly.
Your options then, are:
- Find a factory, or some other method in System.Web that will construct a HttpPostedFile instance for you (my suspicion is you won't find that).
- Implement your own inheriting class of base
HttpPostedFileBase
. This should be simple enough, it's only a small class, and depending on your code making use of it, you might not even have to implement all methods.
- My recommended approach, if possible - Refactor your code to not use
HttpPostedFileBase
, and go with, say, Stream
instead.