asp.net core razor pages upload file
C#
Upload and save to folder link
The following code features a very simple page called UploadFile.cshtml with a form for uploading a file:
@page
@model UploadFileModel
@{
}
<form method="post" enctype="multipart/form-data">
<input type="file" asp-for="Upload" />
<input type="submit" />
</form>
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.IO;
using System.Threading.Tasks;
namespace RazorPagesForms.Pages
{
public class UploadFileModel : PageModel
{
private IHostingEnvironment _environment;
public UploadFileModel(IHostingEnvironment environment)
{
_environment = environment;
}
[BindProperty]
public IFormFile Upload { get; set; }
public async Task OnPostAsync()
{
var file = Path.Combine(_environment.ContentRootPath, "uploads", Upload.FileName);
using (var fileStream = new FileStream(file, FileMode.Create))
{
await Upload.CopyToAsync(fileStream);
}
}
}
}
Also in C#:
- Title
- what is the namespace for textmesh pro
- Category
- C#
- Title
- c# how to have a multiline console.writeline
- Category
- C#
- Title
- c# zip a file
- Category
- C#
- Title
- c# generate random number
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- how to create a variable in C#
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- c# find process by name
- Category
- C#
- Title
- or in unity c#
- Category
- C#
- Title
- how consider the first caracter in Split c#
- Category
- C#
- Title
- c# remove from list in foreach
- Category
- C#
- Title
- c# httpclient azure function authorization
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- .sh script: check if file exist
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- ecs get specific entities with component
- Category
- C#
- Title
- uncaught syntaxerror invalid or unexpected token unity webgl
- Category
- C#
- Title
- change partial view based on select asp.net core
- Category
- C#
- Title
- asp.net core 3.1: cast jObject to dictionary<string,string>
- Category
- C#
- Title
- background color with opacity
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- unity how to load up a scene
- Category
- C#
- Title
- how to reference the position of a game object unity
- Category
- C#
- Title
- constructor in inherited class c#
- Category
- C#
- Title
- convert array object to int[] c#
- Category
- C#
- Title
- how to hide a panel ui unity
- Category
- C#
- Title
- check if string is email c#
- Category
- C#
- Title
- c# round number up
- Category
- C#
- Title
- git set origin
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- how to make a float in C++
- Category
- C#
- Title
- configure 1 to 1 relation ef
- Category
- C#
- Title
- c# windows application get current path
- Category
- C#
- Title
- c# window instantly close
- Category
- C#
- Title
- c# how to sort a list
- Category
- C#
- Title
- asp.net mvc 5 codefirst dropdown list
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- isInstanceOf nunit
- Category
- C#
- Title
- C# .net core convert int to enum
- Category
- C#
- Title
- c# sql duplicate key exception
- Category
- C#
- Title
- c# compile into an exe
- Category
- C#
- Title
- stop ui from clipping wall
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- C# aspnet how to run a migration
- Category
- C#
- Title
- unity 2d enemy field of view
- Category
- C#
- Title
- unity change tag in script
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# repeat string x times
- Category
- C#
- Title
- How to set an expiry date on a program
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- c# lambda expression
- Category
- C#
- Title
- c# duplicate object instance
- Category
- C#
- Title
- how to add object in dictionary in c#
- Category
- C#
- Title
- asp.net render control to string
- Category
- C#
- Title
- c# round number down
- Category
- C#
- Title
- c# throw new exception
- Category
- C#
- Title
- c# datafield change cell background color
- Category
- C#
- Title
- convert string to datetime c#
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- sending data photon c#
- Category
- C#
- Title
- button color uwp c#
- Category
- C#
- Title
- c# how to open file explorer
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- unity get all children
- Category
- C#
- Title
- class selector to property in asp net core dropdown
- Category
- C#
- Title
- get last element of array c#
- Category
- C#
- Title
- unity3d find y position on navmesh
- Category
- C#
- Title
- how to make an object move in unity
- Category
- C#
- Title
- new command - latex
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- c# remove last value from list
- Category
- C#
- Title
- c# checksum
- Category
- C#
- Title
- validating file upload asp.net core mvc
- Category
- C#
- Title
- c# how to check if two lists have same values
- Category
- C#
- Title
- lazy loading c#
- Category
- C#
- Title
- c# get pc ip address
- Category
- C#
- Title
- c# number suffixes
- Category
- C#
- Title
- sort c#
- Category
- C#
- Title
- c# filesystemwatcher double events
- Category
- C#
- Title
- how to reference a child object unity
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- index in foreach c#
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- or in unity
- Category
- C#
- Title
- unity persistent data
- Category
- C#
- Title
- c# get all inherited classes of a class
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- c# docstring
- Category
- C#
- Title
- array syntax c#
- Category
- C#
- Title
- unity check tag
- Category
- C#
- Title
- c# dictionary literal initializer
- Category
- C#
- Title
- wpf binding ancestor codebehind
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- visual studio C# hintergrund bild ändern
- Category
- C#
- Title
- unity rb.addexplosionforce 2d
- Category
- C#
- Title
- c# format number with leading zeros
- Category
- C#
- Title
- c# bool list count true
- Category
- C#