Search code examples
c#bing-ads-api

How to get a CSV as a string or stream in Bing Ads API


I'm using the Bing Ads API to create an online advertising performance dashboard for a customer using the Microsoft.BingAds.SDK from nuget.

Right now stuff works, but I'm having to download the csv report to the file system before reading the data and showing it to the user:

            var t = await manager.DownloadFileAsync(
                new ReportingDownloadParameters()
                {
                    ReportRequest = request,
                    OverwriteResultFile = true,
                    ResultFileDirectory = @"C:\Temp",
                    ResultFileName = @"GL15.csv",
                });

            var csvConfig = new CsvHelper.Configuration.CsvConfiguration()
            {
                Delimiter = ",",
                HasHeaderRecord = true,
                Quote = '"'
            };

            var returnList = new List<BingDailyCampaignPerformance>();

            using (var textReader = System.IO.File.OpenText(@"C:\Temp\GL15.csv"))
            using (var csvReader = new CsvHelper.CsvReader(textReader, csvConfig))
            {
                while (csvReader.Read())
                {
                    returnList.Add(GetRow(csvReader));
                }
            }

This seems less than efficient - why can't I just download the csv to memory in some way, and skip the file system?

Is there a possibility to do this?


Solution

  • With the BulkServiceManager there is an option to read entities directly via temp memory, but currently ReportingServiceManager only supports file download as you noted. Similar to the Bulk download experience we are tracking the "ReportFileReader" feature request, although there isn't yet any firm ETA. Please feel free to add to the Bing Ads Feature Suggestions.