---
title: "How to Download Csv File in Magento 2"
url: "https://dolphinwebsolution.com/how-to-download-csv-file-in-magento-2"
date: "2022-09-26T17:57:39+05:30"
modified: "2023-08-24T09:56:29+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 250
reading_time: "2 min read"
summary: "we will explain you, How to Download Csv File in magento 2. CSV (Comma Separated Value) file is one of the most easy way to import/export magento entity data.download CSV File Programmatically in M..."
description: "we will explain you, How to Download Csv File in magento 2. CSV (Comma Separated Value) file is one of the most easy way to import/export magento entity data..."
keywords: "download csv,csv file magento 2,how to download, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Tax Price Show Only On Product Detail Page"
    url: "https://dolphinwebsolution.com/tax-price-show-only-on-product-detail-page"
  - title: "Magento Extension Offer for Black Friday And Cyber Monday 2023"
    url: "https://dolphinwebsolution.com/blog/magento-extension-offer-for-black-friday-and-cyber-monday/"
  - title: "How to Create Child Theme in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-create-child-theme-in-magento-2"
---

# How to Download Csv File in Magento 2

_Published: September 26, 2022_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/How-To-Download-Csv-File-in-Magento-2-1-1024x536.jpg)

we will explain you, **How to Download Csv File** in magento 2. CSV (Comma Separated Value) file is one of the most easy way to import/export magento entity data.download CSV File Programmatically in Magento 2 by **FileFactory** Class.

## How to Download Csv File in Magento 2

**\\Magento\\Framework\\App\\Response\\Http\\FileFactory** used to create CSV and download CSV by Magento way. **create()** function in **FileFactory.php** is used for create CSV file.

```
<?php
namespace Dolphin\Csv\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Filesystem\DirectoryList;

class GetCsv extends Action
{
    public function __construct(
        Context $context,
        \Magento\Framework\App\Response\Http\FileFactory $fileFactory
    ) {
        $this->fileFactory = $fileFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        $filepath = 'export/allcustomer.csv';
        $downloadedFileName = 'allcustomer.csv';
        $content['type'] = 'filename';
        $content['value'] = $filepath;
        $content['rm'] = 1;
        return $this->fileFactory->create($downloadedFileName, $content, DirectoryList::VAR_DIR);
    }
}
```

Here, *$filepath* is the path of the file under var/ folder. *$downloadedFileName* is the file name when it get downloaded on client side. If ***$content\[‘rm’\]*** is equal to 1 then the file will be deleted from server after it has been downloaded.

If you want to know how can you create csv file programmatically then please check out our blog **“[How to create a CSV file in magento 2](https://dolphinwebsolution.com/how-to-create-a-csv-file-in-magento-2)”.**

I Hope, This instruction will be helpful for you.

If you have any difficulties regarding this blog, do consider them posting in the Comments section below!

I’m here to help.

**Thank you!**


---

_View the original post at: [https://dolphinwebsolution.com/how-to-download-csv-file-in-magento-2](https://dolphinwebsolution.com/how-to-download-csv-file-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:14:32 UTC_  
