Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.


What I have tried:

i tried this code below converting from c# to VB.NET, but says "Move is not a member of MultiPartFileData".


VB
<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
Posted
Updated 2-May-20 10:23am
Comments
F-ES Sitecore 27-Apr-20 10:10am    
Try fully qualifying File

System.IO.File.Move(localFileName, filePath)

the compiler might be getting "File" confused with your "file" variable.
SulfySul 27-Apr-20 12:00pm    
Thank you, that resolved the problem

1 solution

as @F-ES Sitecore suggested, using fully qualified file resolved my problem
System.IO.File.Move(localFileName, filePath)


the compiler was getting "File" confused with my "file" variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900