Add local file to HttpPostedFileBase

Hi All,
Advance thanks.
My existing page has upload button and can do upload feature using post method and  finally add the files from HttpRequest to  HttpPostedFileBase. This works fine.

My issue is
Have to do upload but not through drag and drops or selecting from the folder. Instead, i need to attach the local file into HttpPostedFileBase.

HttpPostedFileBase fileBase = load file using  File.Open(path, FileMode.Open);

I know it is not possible because it's  abstract class. My issue is i have to use HttpPostedFileBase but i need to load a local file into it.

please help.

Kind regards,
Pooja
poojasureshkumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi Pooja,

When you say local file is this a file on the server or on the client side?

Regards,
Chinmay.
0
poojasureshkumarAuthor Commented:
server side
0
Chinmay PatelChief Technical NinjaCommented:
Alright. And I understand this is an ASP.Net code so what exactly you want to do with this local file by getting it inside HttpPostedFileBase . Please don't mind but I want to understand if we can come up with something better by understanding your business requirements.
0
poojasureshkumarAuthor Commented:
Hi Chinmay,
I got the solution. Thanks!
var binary = {here am getting binary data for the server file..}
using (var client = new HttpClient())
     {
         using (var content =
             new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
         {
             content.Add(new StreamContent(new MemoryStream(binary)), "PATH", "FileName");

              using (
                 var message =
                     await client.PostAsync("web api url", content))
              {
                  var input = await message.Content.ReadAsStringAsync();

                return null;
              }
          }
     }


Kind regards,
Pooja
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.