Reputation: 14511
I have a method that takes an HttpPostedFileBase as a parameter, but I'm unsure how I can assign a local file as a HttpPostedFileBase.
string httpPostedFileBase = @"C:\SVN - Apps\trunk\files\230.flv";
var uploadedFile= FileAndMediaService.UploadFile(httpPostedFileBase, fileInfo);
Upvotes: 1
Views: 4140
Reputation: 13965
I've never tried it, but according to the answer to this post, you can create a derived class that will be accepted in place of HttpPostedFileBase
. Since you have a file on disk and the question involved a byte array, you'll have to read the file into a byte array (using classes in the System.IO
namespace) or make other modifications.
Another option would simply be to write a small MVC page (since you've tagged this entry with MVC I assume that's what you're doing) and just upload the file and go from there. But if you have multiple files to upload, you might want to go the derived class route.
Upvotes: 0
Reputation: 47375
If the file already exists locally on the hard drive of the machine running MVC (through IIS or IIS Express), then it is not POSTed via HTTP. HttpPostedFileBase is an object for converting a file upload obtained from an HTTP POST.
If you want to work with a file that is already on the server, look at the classes in the System.IO namespace.
Upvotes: 2