Fixing WFFM attachment URL in Excel that exported from Sitecore
Have you ever seen “sitecore://web/{358B0E87-893A-45A8-A707-D19A32962DFF}?lang=en&ver=1” this value? If you are using WFFM with attachment field, you are most likely going to see this value in the Excel file downloaded from the form. This is because WFFM doesn’t manipulate data during exporting data into Excel, which means data formatting will be the same as it’s stored in the database.
Understand how it works
For solving the issue, let’s get understood how it works. First of all, what’s the Guid in the URL? It’s a media library item ID. If you search the ID in Sitecore, you can find that item in media library. The attachment will be created in Media Library Once the form is submitted. By default, it’s stored in Master database, however you are allowed to change to Web database with below settings. In my case, I don’t want to change this to store in web database, as the attachment is not mean to be accessible from public.<setting name="WFM.MasterDatabase" value="web" />
The attachment is just a media library item, which you use MediaManager.GetMediaUrl for getting the URL (As shown in screenshot below)
Solutions
Now, you should understand how it works, and let’s fix the export value together. First of all, we need to find out which pipeline is for exporting the data into Excel. Luckily, It’s not so hard to find. It’s registered in the exportToExcel pipeline:
Next is to customize the ExportFormDataToExcel function, here is the code snippets
Finally, if you export data into Excel again, the wired URL is fixed with a valid media item URL!.