Image Direct Download from Server URL Path in binary mvc c# - B M SOLUTION
  • Image Direct Download from Server URL Path in binary mvc c#





     create PROCEDURE [dbo].[usp_ImportImage] --  '1' 

    (


         @PicName NVARCHAR (100) --1001


       )


    AS


    BEGIN


     declare @ImageFolderPath NVARCHAR (1000)


       , @Filename NVARCHAR (1000)


    set @ImageFolderPath='C:\BLIPInvoiceDownloaded\05AAFCB7044K1ZN294167055556606.jpg';


    -- select @Filename=  InvoiceImage from BillDetails where id=@PicName


     --select   InvoiceImage from BillDetails


     --select @Filename=  SUBSTRING(InvoiceImage, 40,50)  from BillDetails where id=@PicName




    --select len ('C:\inetpub\wwwroot\testing\ImageInvoice')

    --set @Filename='05AKAPK1877F1ZD19699412913597.jpg'


       DECLARE @Path2OutFile NVARCHAR (2000);


       DECLARE @tsql NVARCHAR (2000);


       SET NOCOUNT ON


     

      --SELECT STRING_SPLIT ('C:\inetpub\wwwroot\testing\ImageInvoice\05AKAPK1877F1ZD19699412913597.jpg' , \ )  AS ExtractString;

     

     

     --select @Filename=  SUBSTRING(InvoiceImage, 40,50)  from BillDetails where id=@PicName


     

       


       SET @Path2OutFile = 


             @ImageFolderPath


            


       SET @tsql = 


                   ' SELECT ' + '''' + @PicName + '''' + ', * ' + 


                   'FROM Openrowset( Bulk ' + '''' + @Path2OutFile + '''' + ', Single_Blob) as img'


       EXEC (@tsql)


       SET NOCOUNT OFF


    END


    --select * from BillDetails where Id='1'




    <a href="/Admin/DownloadInvoice?Id=@item.Id" class="btn-link text-dark"> Download test </a>



    public ActionResult DownloadInvoice(string Id)

            {

                byte[] bytes;

                SqlConnection con = new SqlConnection(connection);

                SqlCommand cmd = new SqlCommand("usp_ImportImage", con);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@PicName", Id);

                cmd.Connection = con;

                con.Open();

                SqlDataReader sdr = cmd.ExecuteReader();

                sdr.Read();

                bytes = (byte[])sdr["BulkColumn"];

                con.Close();

                Response.Clear();

                Response.Buffer = true;

                Response.Charset = "";

                Response.Cache.SetCacheability(HttpCacheability.NoCache);

                Response.AppendHeader("Content-Disposition", "attachment; filename=" + Id + ".jpg");

                Response.BinaryWrite(bytes);

                Response.Flush();

                Response.End();


                string message = "Please Check this File in C Drive (BLIPInvoiceDownloaded) Folder! Your File Downloaded Successfully";

                return Json(new { result = message });


            }

  • You might also like

    No comments :

    Post a Comment