2
System.Web.UI.Request

is not available in .net core so the question is about the alternative of this namespace.

I need to read the file content for upload on server. in version 4.5 of .net, i was doing like HttpPostedFile file = Request.Files["content"]; but now this is not working in .net core. I need to know if there is any alternative of best example of file uploading in .net core please share.

following is my old code.

HttpPostedFile file = Request.Files["content"];
byte[] fileData = null;
                    using (var binaryReader = new BinaryReader(file.InputStream))
                    {
                        fileData = binaryReader.ReadBytes(file.ContentLength);
                    }

                    var fileName = Request.Form["fileName"];

                    FileBusiness.SaveFile(domain, new Guid(token), fileName, fileData, true);
                    Response.Write("Normal file uploaded");

I am asking for the upload file functionality in RC1 which is in think is not available in RC1 but i have found in .net core 1.0 RTM libraries. I need to know if there is any way to upload the file in .net core RC1?

2
  • What middleware are you using? From the docs: ASP.NET Core has a number of architectural changes that result in a much leaner and modular framework. ASP.NET Core is no longer based on System.Web.dll. It is based on a set of granular and well factored NuGet packages. This allows you to optimize your app to include just the NuGet packages you need. docs.asp.net/en/latest/intro.html Commented Aug 8, 2016 at 7:35
  • 2
    Possible duplicate of How to get HttpContext.Current in ASP.NET Core? Commented Aug 8, 2016 at 7:38

1 Answer 1

1

If you are using ASP.NET Core and enctype="multipart/form-data" form then for reading uploaded file use IFormFile (var file = Request.Form.Files["fileUpload"]) and its CopyTo, CopyToAsync or OpenReadStream methods.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the suggestion, i have tried the mikesdotnetting.com/article/288/… link and it is succesfully uploading the file in .net core. But the article is on .net core 1.0 release and i am using RC1 in my project. Either i need to upgrade my whole project for this or is there any way that i can use IForm type of library in RC1?
I do not recommend you to mix RC1 and RTM libraries. Upgrading to RTM is recommended way, because all 3rdparty libraries you use will move to RTM somewhere, causing your project to fetch more and more core RTM libraries as their dependencies.
Thank you for the suggestion. I will either stay at RC1 or move totally to RTM. My point was, if there is any way of upload the file on server in RC1 so i can use it otherwise i will have to upgrade the whole project in RTM. One more thing, in RC1 i am using framework dnx451 but i think this frameowrk does not have the support in RTM. am i right?
I dont' have RC1 on my machine anymore. You can "Go to declaration" on type that is returned from Request.Form.Files in VS and inspect it methods - may be it has something like SaveAsAsync or similar.
Nuget package Microsoft.AspNetCore.Mvc supports net451 target moniker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.