ASP. NET 5 upload file stored via virtual path

Source: Internet
Author: User

Put the code on first.

[HttpPost] Publiciactionresult importteaching (iformfile file) {stringRoot =@"temp/teachingfile/"; stringPhypayh =EVN.            MapPath (root); if(File! =NULL)            {                varParsedcontentdisposition =contentdispositionheadervalue.parse (file.                Contentdisposition); varOriginalname = ParsedContentDisposition.FileName.Replace ("\"",""); File. SaveAs (Phypayh+originalname); }            Else{modelstate.addmodelerror ("","No file selected"); returnView (); }            returnRedirecttoaction ("Index"); }

You must first get the ihostingenvironment inside the service.

The following code

  [fromservices]        publicsetget;}

Note: this

Ihostingenvironment is automatically registered to the service when it is started. can be directly obtained

Special attention:

Now the virtual path is written in a different way before the MVC5 is similar:string root = "~/livefile/";

Now is:string root = "livefile/";

I have tried many times before in accordance with MVC5 's wording.

ASP. NET 5 upload file stored via virtual path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.