title: How to import image files to database on button click in asp.net mvc
body: <p>I want to move <strong>all</strong> the image files in the folder called <strong>Uploads</strong> to database table.i've tried following things to do so.but it is not working neither i am getting any error.Please help me with this   </p>
  
  <p>here is my contoller action method</p>
  
  <pre><code> [HttpPost]
      public bool Upload(int? id)
      {
          try
          {
              //Path of the images in the upload folder
              var fullpath = Directory.GetFiles(Server.MapPath("~/Uploads"));
              List&lt;string&gt; fullPath = new List&lt;string&gt;();
              foreach (var path in fullPath) 
              {
                  db.Execute("ImportImage"); //stored procedure
              }
              return true;
  
          }
          catch (Exception ex)
          {
              throw ex;
  
          }
  
      }
  </code></pre>
  
  <p>here is my view</p>
  
  <pre><code>@using (Html.BeginForm("Upload", "Document", FormMethod.Post))
                              {
                                  &lt;input type="button" value="Upload Image" id="uploadImg" class="btn btn-primary" /&gt;
                              }
  
      &lt;script&gt;
          $("#uploadImg").click(function () {
              $.ajax({
                  'url': "@Url.Action("Upload", "Document")",
                  'type': "POST"
                  })
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>here is my stored procedure</p>
  
  <pre><code>CREATE PROCEDURE dbo.ImportImage (
     @ImageFolderPath NVARCHAR (1000)
     )
  AS
  BEGIN
     DECLARE @Path2OutFile NVARCHAR (2000);
     DECLARE @tsql NVARCHAR (2000);
     SET NOCOUNT ON
     SET @Path2OutFile = CONCAT (
           @ImageFolderPath
           ,'C:\Users\HP\source\repos\ClickLockDB2\EAStarter\Uploads'
           );
     SET @tsql = 'insert into ImagesScanned (ImagesScannedId, DocumentId, ScanPage) ' +
                 ' SELECT * ' + 
                 'FROM Openrowset( Bulk ' + '''' + @Path2OutFile + '''' + ', Single_Blob) as img'
     EXEC (@tsql)
     SET NOCOUNT OFF
  END
  GO
  </code></pre>
  
  <p>my table in which i want to move that images
  Model</p>
  
  <pre><code>public partial class ImagesScanned  
  {
      public int ImagesScannedId { get; set; }
      public int? DocumentId { get; set; }
      public byte[] ScanPage { get; set; }
  }
  </code></pre>