I have a web application that has a functionality that consists in put a list of images in a folder (on the same server that the web application) and then process that images to upload them to the web application format.
For that action i have a list of FileInfo objects and i need to convert those FileInfo objects into HttpPostedFileBase because the Upload method uses this kind of object to work.
What's the best way to make this conversion?
You need to derive from
HttpPostedFileBaseand implements its members, mainly theStreammember. Return aFileStream. Make sure to dispose of that stream eventually. Leaking file handles on a web server can be deadly.I would recommend an entirely different approach instead. Don't pass in an
HttpPostedFileBase. Pass in aStreamor maybe a custom class. That, of course, requires you to extract the upload logic into a helper method. Don't call the web methodUpload, call the helper. That way you don't need to create fake ASP.NET objects.