![get file path of httppostedfilebase get file path of httppostedfilebase](https://i.stack.imgur.com/UQPua.png)
However, if you wish you can make changes according to your requirement. Note: I have not made any changes in the WebApiConfig file. The function returns a string value, as a confirmation, saying if the loaded or has failed.
![get file path of httppostedfilebase get file path of httppostedfilebase](https://our.umbraco.com/media/upload/6de5504f-6d5c-4227-b5de-365f8e3f2f38/Membership-Avatar.jpg)
The controller has a public function called UploadFiles(), which is called by the Ajax using a POST request. Return iUploadedCnt & " Files Uploaded Successfully" SaveAs(sPath & Path.GetFileName(hpf.FileName)) If Not File.Exists(sPath & Path.GetFileName(hpf.FileName)) Then ' CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. Request.Filesįor iCnt As Integer = 0 To hfc.Count - 1 ' CHECK THE FILE COUNT. SPath = .MapPath("~/locker/")ĭim hfc As System.Web. ' DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES. You may later name the folder as you wish. You will upload your files in this folder. Note: You must first create a folder in the root directory of your project called locker. Return iUploadedCnt + " Files Uploaded Successfully" SaveAs(sPath + Path.GetFileName(hpf.FileName)) If (!File.Exists(sPath + Path.GetFileName(hpf.FileName))) CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES. Public class FileUploadController : ApiController From the Template dropdown list, choose Empty MVC controller and click the Add button. In the Add Controller window, type FileUploadController in the Controller Name box. By voting up you can indicate which examples are most useful and appropriate. Find Controllers folder, right click it and choose Add and Controller…. Here are the examples of the csharp api class (string) taken from open source projects.
![get file path of httppostedfilebase get file path of httppostedfilebase](https://i.stack.imgur.com/3oP7I.jpg)
Open the Solution Explorer window in the project. Therefore, let’s create the Controller for our WebAPI. If you are newbie in Web API, then I would recommend you to check the below link for step by step creation and implementation of your first Web API application. From the Project Template under New ASP.NET MVC 4 Project, select Web API template and press OK. Choose the language you prefer and select Web -> Asp.Net MVC4 Web Application. In the New Project window, you will find a list of “Installed Templates”. Start Visual Studio and from the top left choose File -> New Project. You can call a Web API controller from any client application, which is capable of making an http POST request either using jQuery Ajax or XMLHttpRequest object. The controller in the API has the code to upload multiple files and I have written it for C# and VB developers. Here, in this post I have written a simple file upload procedure in Asp.Net Web API. If you are looking for a solution on file upload, then you have come to the right place.