Retrieve CSV file uploaded to CRM standard import

In some rare cases you wish you could retrieve the file uploaded to CRM. Unfortunately, there is no way that CRM is going to return you this file...

But luckily, in OnPremise and some Partner Hosted environments, it is possible to access the underlying database. This is where you can find the data for each of the rows which allow you to recreate the CSV (or XML) file.

The following query will retrieve all the relevant information:

SELECT ifb.ImportFileId,
    Source,
    HeaderRow,
    Data,
    LineNumber
   
  FROM ImportDataBase idb
  LEFT OUTER JOIN ImportFileBase ifb ON idb.ImportFileId = ifb.ImportFileId
  WHERE ifb.ImportFileId = 'DEAC184E-D7CA-E311-B83A-00155D083043'
  ORDER BY Source, LineNumber


Of course you'll need to change the importfileid GUID or change this to select based on the source (the name of the imported file). Then Copy the header row, followed by each of the data rows and your source file is recreated.

Good luck!