Как загрузить файл с помощью ASP.NET проект веб-api?
i have a web API project to be consumed from mobile applications and i was trying to make a file upload controller. there are few resources in C# and i don't find anything useful for VB.NET.
Что я уже пробовал:
i tried this code below converting from c# to VB.NET, but says "Move is not a member of MultiPartFileData".
<pre>Imports System Imports System.Collections.Generic Imports System.IO Imports System.Linq Imports System.Net Imports System.Net.Http Imports System.Threading.Tasks Imports System.Web Imports System.Web.Http Namespace HelloWorld.Controller Public Class FileUploadingController Inherits ApiController <HttpPost> <Route("api/FileUploading/UploadFile")> Public Async Function UploadFile() As Task(Of String) Dim ctx = HttpContext.Current Dim root = ctx.Server.MapPath("~/App_Data") Dim provider = New MultipartFormDataStreamProvider(root) Try Await Request.Content.ReadAsMultipartAsync(provider) For Each file In provider.FileData Dim name = file.Headers.ContentDisposition.FileName name = name.Trim(""""c) Dim localFileName = file.LocalFileName Dim filePath = Path.Combine(root, name) File.Move(localFileName, filePath) Next Catch e As Exception Return $"Error: {e.Message}" End Try Return "File uploaded!" End Function End Class End Namespace
F-ES Sitecore
Попробуйте полностью квалифицировать файл
System.IO.File.Переместить(localFileName, filePath)
компилятор может перепутать "файл" с вашей переменной "файл".
SulfySul
Спасибо, что решили эту проблему