Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

xrm.navigation.openfile doesn't work in Internet Explorer or Edge Legacy

(0) ShareShare
ReportReport
Posted on by 35

Hello,

Setup: Dynamics 365 CRM v9 on-prem, logged in as Sys Admin

I have a javascript web resource on an entity form that generates a .EML file. This file is then opened via the Xrm.Navigation.OpenFile() method. I am using the default Web UI.

In Chrome it downloads the file fine and when I open it it will open in an outlook window and show everything (To,CC,Subject, Body[HTML] and Attachment). I noticed that the file is encoded in ANSI by default.

In IE 11 or Edge Legacy, however, it fails to download and generates the folllowing error: The URI to be decoded is not a valid encoding. I fiddled with the .EML and replaced the HTML Body with something simple and it does download but I noticed the encoding is Unicode. If I try to open this file it will show up in an Outlook window but is blank. If I save the file in notepad with a different encoding like ANSI or UTF8 it then opens fine with Outlook.

I have been trying to find javascript code to change the encoding of my .EML string to UTF-8 before calling open File but haven't found anything.

The code is something along the lines of:

// attachment details retrieved via a webApi call
var documentbody = results.entities[0]["documentbody"];
var filename = results.entities[0]["filename"];
var mimetype = results.entities[0]["mimetype"];

var testEML = "To: " + toAddresses + "\r\n";
testEML += "CC: " + ccAddress + "\r\n";
testEML += "Subject: " + subject + "\r\n";
testEML += "X-Unsent: 1\r\n";
testEML += "Content-Type: multipart/mixed; boundary=boundary_text_string\r\n";
testEML += "\r\n";
testEML += "--boundary_text_string\r\n";
testEML += "Content-Type: text/html; charset=Windows-1252\r\n";
testEML += "\r\n";
testEML += "<html><body>HELLO WORLD!</body></html>" + "\r\n";
testEML += "\r\n";
testEML += "--boundary_text_string\r\n";
testEML += "Content-Type: " + mimetype + "; name=" + filename + "\r\n";
testEML += "Content-Transfer-Encoding: base64\r\n";
testEML += "Content-Disposition: attachment\r\n";
testEML += "\r\n";
testEML += documentbody + "\r\n";
testEML += "\r\n";
testEML += "--boundary_text_string--";

// Step 5: Show EML File (which will open an outlook email window ready to be sent)
file = {};
file.fileContent = btoa(testEML);
file.fileName = "notice-" + fieldMappings.TrackingNumber + ".eml";
file.mimeType = "message/rfc822"; // EML standard - tried adding charset="UTF-8" but didn't do anything

parent.Xrm.Navigation.openFile(file).then(function (success)
{
console.log("File downloaded successfully.");
}, function (error)
{
// does not work in Edge or IE (The URI to be decoded is not a valid encoding)
console.log("File was not downloaded.");
console.log(error.message);
});

 Any ideas? Currently I just tell users to use Chrome... but I would like it to work with IE and Edge. 

Thanks,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 106

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

Overall leaderboard

Product updates

Dynamics 365 release plans