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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to change from utf8 to utf16 When sending files to azure blob

(0) ShareShare
ReportReport
Posted on by 1,967

Hi,

i'm sending files to azure blob using Microsoft.Windows.Storage

And when they open it in notepad they get an error because of the currency symbol

So how xan i change it by code to utf-16

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi IntegrationBeginner,

    I think that it should not be the responsibilityof the file sender (who transfers the file from A to B), instead it should be the responsibility of the file creator. Perhaps you can talk with the person/company/developer who created the file and ask them to use UTF-16?

  • .. Profile Picture
    1,967 on at

    Hi Nikolas,

    I created the file by code and send it to azure blob. So when they opened the file they didn't get the correct currency symbol. It's already utf8.. I need to change it utf16

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi IntegrationBeginner,

    then I guess this issue is not so much related to "sending files to azure blob" but rather the creation of the file. And the relevant part is the code where you create the file. Do you agree?

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    UTF-8 can represents exactly the same characters as UTF-16, therefore your problem seems to be caused by something else.

    Can you please tell us more about your problem with the currency symbol, how you identified the encoding of the file and what code you're using to create file content?

  • .. Profile Picture
    1,967 on at

    Hi Nikolaos,

    Yes true. I'm using commaStreamIo

    Hi Martin,

    To be honest i don't know that the issue is exactly. But i was told that they weren't able to process the file and that we need to switch that to Utf-16. So myabe the was a problem with the pound symbol or sth.

    And i'm using commaStreamIo

    Can i change that using commaStreamIo?

  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    If I was you, I would get more information about the problem. It looks likely to me that you (and we with you) are solving a wrong problem. You also can't test your changes if you don't even know how to reproduce the problem.

    Anyway, the constructor of TextIo allows you to set the encoding in the third argument. Check out CommaStreamIo - I would expect it to be the same.

    Note that according to the documentation, UTF-16 is already the default value for TextIo.

  • .. Profile Picture
    1,967 on at

    Hi Martin, 

    I think they are sure of the problem that their system required UTF-16

    it seems we can't set the encoding for commaStreamIo, unless i'm missing sth ( we can't use the new method, and i can only use the static method constructForWrite)

    Here's what i'm doing

    CommaStreamIo comma = CommaStreamIo::ConstructForWrite();
    comma.OutFieldDelimiter('|');
    comma.WriteExp(lineContainer); //assume container is filled
    
    System.IO.Stream stream = comma.getStream();
    stream.Postion = 0;
    
    //then i use Microsoft.Windows.Storage to upload the file
    cloudBlockBlob.UploadFromStream(stream,null,null,null);

    Any idea how can i change the UTF8 to UTF-16 based on my code?  or what should i do? as it seems there is no code page variable for encoding like textIo

  • Suggested answer
    Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    I looked into code and it seems that CommaStreamIo doesn't allow you to set encoding. But you can easily add this capability by yourself - create a child class or add an extension method.

    For example:

    public static CommaStreamIo constructForWriteWithEncoding(System.Text.Encoding _encoding)
    {
    	InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
    	perm.assert();
    
    	System.IO.MemoryStream stream = new System.IO.MemoryStream();
    	System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, _encoding);
    	
    	CommaStreamIo io = new CommaStreamIo();
    	io.setStream(stream);
    	io.setWriter(writer);
    
    	return io;
    }

  • .. Profile Picture
    1,967 on at

    Hi Martin,

    I can't do an extension class because the new method for commaStreamIo is protected

    So i had to create a child class.

    However, how can i pass UTf16 to the parameter System.Text.Encoding.. It seems this class has only utf8, utf7 and utf32.

    So how can i call the method i created in the child class with utf16? 

  • Suggested answer
    Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    You're too quick in giving up. You can still use an extension method if you want - just call a factory method and then create and set writer once more:

    public static CommaStreamIo constructForWriteWithEncoding(System.Text.Encoding _encoding)
    {
    	InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
    	perm.assert();
    	
    	CommaStreamIo io = CommaStreamIo::constructForWrite();
    	System.IO.StreamWriter writer = new System.IO.StreamWriter(io.getStream(), _encoding);
    	io.setWriter(writer);
    
    	return io;
    }

    If you don't know how to use the Encoding class, open the documentation and learn from it. Let me quote it:

    UnicodeEncoding encodes Unicode characters using the UTF-16 encoding. Both little endian and big endian byte orders are supported. Also available through the Unicode property and the BigEndianUnicode property.

    There are indeed many more properties than the three that you mentioned.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans