I Export the data from database using kentico API in C#

Ramakrishnan G asked on August 19, 2019 16:56

I Export the data from COM_Address table using kentico API in C#. The file dowloading on desktop path. How to chnage the path? and my requirements is If I click the download button save in downloads path.

I using below code. var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), "addresses-upload-template.xls"); var dataExportHelper = new DataExportHelper(addresses.Result); using (System.IO.FileStream output = new System.IO.FileStream(path, FileMode.Create)) { dataExportHelper.ExportData(DataExportFormatEnum.XLSX, output); }

Recent Answers


Ketan Hirapara answered on August 20, 2019 10:58 (last edited on August 20, 2019 11:56)

Hi,

You can use below code to set your download location to any folder of your machine.

        var addresses = AddressInfoProvider.GetAddresses().Columns("AddressName", "AddressLine1",
         "AddressLine2", "AddressCity", "AddressZip", "AddressPhone");

        string myPath = @"D:/DemoFilePath/"; //Can set your desired path here.

        var path = Path.Combine(myPath, "addresses-upload-template.xls");
        var dataExportHelper = new DataExportHelper(addresses.Result);
        using (System.IO.FileStream output = new System.IO.FileStream(path, FileMode.Create))
        {
            dataExportHelper.ExportData(DataExportFormatEnum.XLSX, output);
        }
        if (home == null)
        {
            return HttpNotFound();
        }
2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.