WEB API code to Create Folder Dynamically and Save Files Into The Folder,
Then call / consume web api into jQuery

In this article will explain step by step process, Consume WEB API into jQuery to create a folder dynamically into a project folder and upload selected files into the folder using c# example

Technology : - asp.net web api, jQuery html element with c# coding


step -1 create a new web api controller in the controllers folder and give name UploadController,after that add the below code

           
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.IO;

namespace File_Upload_Webapi.Controllers
{
    public class UploadController : ApiController
    {
        [HttpPost]
        public void uploadfiles()
        {
            string foldercreate = HttpContext.Current.Server.MapPath("~/Upload/");
            if(!Directory.Exists(foldercreate))
            {
                Directory.CreateDirectory(foldercreate);
            }

            if(HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var fileupload = HttpContext.Current.Request.Files["Uploadfiles"];
                if(fileupload!=null)
                {
                    var savefiles = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/"),fileupload.FileName);
                    fileupload.SaveAs(savefiles);
                }
            }
        }
    }
}
	

step 2 the next we require the web api url, to consume into the jQuery. Press f5 to run the application and the output in the browser you will get in the xml format. With some error message The requested resource does not support http method 'GET', because we are posting the data. So, just ignore the error message just copy the web api url
step - 3 now, add a new html page to the project and consume web api url into Ajax jQuery Snippert
	
 <!DOCTYPE html>
<html>
<head>
    
	
    
</head>
<body>
   <form>
        

WEB API, Create Folder Dynamically and Save Files Into The Folder

Consume web api into jQuery


Select File
</form> </body> </html>

Free Top Udemy Courses

Read Complete Article → sadfasfasfd asdfasdfsa asfasfd asdfasdf asdfasfdsa asdfasdf