web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript: Create File in Charset Windows-1252

(0) ShareShare
ReportReport
Posted on by 472

Hello

I want to create an vCard - Export - Button. The first step is to collect all information needed and write them in an extra text field. It's all set up with the right tags for a vCard like the Definition.

Then I found a JavaScript, which can create a text file. There I changed the file ending to vcf. The problem now is, that the file is exported in UTF-8. When I import the vcf in Outlook, the ä ö and ü are ö or ÃƒÂ¼.

How can I export the File in Windows-1252? I really tried everything for MimeType.

function onClick() {
    var filename = Xrm.Page.getAttribute("fullname").getValue();
    var Content = Xrm.Page.getAttribute("eis_vcard").getValue();
    download(Content, filename + ".vcf", 'text/vcard;");
}


function download(strData, strFileName, strMimeType, encoding) {
    var D = document,
        a = D.createElement("a");
    strMimeType = strMimeType || "application/octet-stream";


    if (navigator.msSaveBlob) { // IE10
        return navigator.msSaveOrOpenBlob(new Blob([strData], { encoding: encoding, type: strMimeType }), strFileName);
    } /* end if(navigator.msSaveBlob) */


    if ('download' in a) { //html5 A[download]
        a.href = "data:" + strMimeType + "," + encodeURIComponent(strData);
        a.setAttribute("download", strFileName);
        a.innerHTML = "downloading...";
        D.body.appendChild(a);
        setTimeout(function () {
            a.click();
            D.body.removeChild(a);
        }, 66);
        return true;
    } /* end if('download' in a) */


    //do iframe dataURL download (old ch+FF):
    var f = D.createElement("iframe");
    D.body.appendChild(f);
    f.src = "data:" + strMimeType + "," + encodeURIComponent(strData);

    setTimeout(function () {
        D.body.removeChild(f);
    }, 333);
    return true;
} /* end download() */


*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: JavaScript: Create File in Charset Windows-1252

    use 'UTF-16BE' instead of 'UTF-8'

  • Raffaele Sorra Profile Picture
    472 on at
    RE: JavaScript: Create File in Charset Windows-1252

    And where and how do I implement this in the code?

    I tried so many variations...

    download(Content, filename + ".vcf", 'text/vcard;");
    
    download(Content, filename + ".vcf", 'text/plain;charset=Windows-1252;');
    
    download(Content, filename + ".vcf", 'text/text;");
    
    ...
    
    ...


  • Community Member Profile Picture
    on at
    RE: JavaScript: Create File in Charset Windows-1252

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-16BE">

    <script src="" charset="UTF-16BE"></script>

    var http =new GetXmlHttpObject();

     //Send the proper header information along with the request

     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-16BE;");

    If my response is helps you, please mark as "Verified"

  • Raffaele Sorra Profile Picture
    472 on at
    RE: JavaScript: Create File in Charset Windows-1252

    We solved this case in another way. Thanks anyway.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans