How: Setting UTF8 as an application wide text encoding format

XmlTextReader myXmlReader = new XmlTextReader(args[0]);
string	en = myXmlReader.Encoding.EncodingName;
//Console.WriteLine(x);

Error:

Unhandled Exception: System.NullReferenceException: Object 
reference not set to
an instance of an object.

HOW CAN I GET THE ENCODING NAME ? Basically determine the 
encoding type.

Also How can I "set" an application wide Encoding ? I want 
all modules and everything to stick to and conform to UTF-
8.

But somehow some methods automatically go to UTF-16
0
xmlguy (13)
10/10/2003 10:48:48 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
647 Views

Similar Articles

[PageSpeed] 50

xmlguy,

1) What's args[0] in your example? Does it contain any Xml? In that case you
first have to pass that sting off to a StringReader. If it's a path to a
file then it's OK.

You have to actually start reading the contents of the XML document. You do
this by calling the Read() method for the first time. This sample code works
for me:

string xml = "<foo>bar</foo>";
XmlTextReader reader = new XmlTextReader( new StringReader( xml ) );
//go to the first node
reader.Read();
System.Diagnostics.Debug.WriteLine( reader.Encoding.EncodingName );


2) All strings object in the framework are unicode encoded. You can work
with the various encoding classes in System.Text.Encoding to create byte[]s
and MemoryStreams that contain text encoded in a different encoding scheme.
You cannot change the encoding of string objects.

-- 
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"xmlguy" <xmlguy@yahoo.com> wrote in message
news:0a1001c38f80$ab042fb0$a001280a@phx.gbl...
> XmlTextReader myXmlReader = new XmlTextReader(args[0]);
> string en = myXmlReader.Encoding.EncodingName;
> //Console.WriteLine(x);
>
> Error:
>
> Unhandled Exception: System.NullReferenceException: Object
> reference not set to
> an instance of an object.
>
> HOW CAN I GET THE ENCODING NAME ? Basically determine the
> encoding type.
>
> Also How can I "set" an application wide Encoding ? I want
> all modules and everything to stick to and conform to UTF-
> 8.
>
> But somehow some methods automatically go to UTF-16


0
10/11/2003 2:13:59 AM
I guess I should have specified. 

args[0] on the commandline is the name of a .xml file 
containing XML with UTF-8 as its encoding.

That is the wierd thing as to why everything defaults to 
UTF-16 ?

>-----Original Message-----
>xmlguy,
>
>1) What's args[0] in your example? Does it contain any 
Xml? In that case you
>first have to pass that sting off to a StringReader. If 
it's a path to a
>file then it's OK.
>
>You have to actually start reading the contents of the 
XML document. You do
>this by calling the Read() method for the first time. 
This sample code works
>for me:
>
>string xml = "<foo>bar</foo>";
>XmlTextReader reader = new XmlTextReader( new StringReader
( xml ) );
>//go to the first node
>reader.Read();
>System.Diagnostics.Debug.WriteLine( 
reader.Encoding.EncodingName );
>
>
>2) All strings object in the framework are unicode 
encoded. You can work
>with the various encoding classes in System.Text.Encoding 
to create byte[]s
>and MemoryStreams that contain text encoded in a 
different encoding scheme.
>You cannot change the encoding of string objects.
>
>-- 
>HTH
>Christoph Schittko [MVP]
>Software Architect, .NET Mentor
>
>"xmlguy" <xmlguy@yahoo.com> wrote in message
>news:0a1001c38f80$ab042fb0$a001280a@phx.gbl...
>> XmlTextReader myXmlReader = new XmlTextReader(args[0]);
>> string en = myXmlReader.Encoding.EncodingName;
>> //Console.WriteLine(x);
>>
>> Error:
>>
>> Unhandled Exception: System.NullReferenceException: 
Object
>> reference not set to
>> an instance of an object.
>>
>> HOW CAN I GET THE ENCODING NAME ? Basically determine 
the
>> encoding type.
>>
>> Also How can I "set" an application wide Encoding ? I 
want
>> all modules and everything to stick to and conform to 
UTF-
>> 8.
>>
>> But somehow some methods automatically go to UTF-16
>
>
>.
>
0
xmlguy (13)
10/13/2003 5:10:44 PM
The encoding of the data in your file becomes irrelevant once you use a
StreamReader to read the file content into a strings. Strings are always
UTF-16 in .NET. You have to work with byte[] instead of strings if you need
to preserve the character encoding.

Does it matter what format the data is encoded in within your application?
Or do you simply need to be able to write it back to a file in UTF-8
encodeing?
-- 
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"xmlguy" <xmlguy@yahoo.com> wrote in message
news:041501c391ac$efde1fa0$a301280a@phx.gbl...
> I guess I should have specified.
>
> args[0] on the commandline is the name of a .xml file
> containing XML with UTF-8 as its encoding.
>
> That is the wierd thing as to why everything defaults to
> UTF-16 ?
>
> >-----Original Message-----
> >xmlguy,
> >
> >1) What's args[0] in your example? Does it contain any
> Xml? In that case you
> >first have to pass that sting off to a StringReader. If
> it's a path to a
> >file then it's OK.
> >
> >You have to actually start reading the contents of the
> XML document. You do
> >this by calling the Read() method for the first time.
> This sample code works
> >for me:
> >
> >string xml = "<foo>bar</foo>";
> >XmlTextReader reader = new XmlTextReader( new StringReader
> ( xml ) );
> >//go to the first node
> >reader.Read();
> >System.Diagnostics.Debug.WriteLine(
> reader.Encoding.EncodingName );
> >
> >
> >2) All strings object in the framework are unicode
> encoded. You can work
> >with the various encoding classes in System.Text.Encoding
> to create byte[]s
> >and MemoryStreams that contain text encoded in a
> different encoding scheme.
> >You cannot change the encoding of string objects.
> >
> >-- 
> >HTH
> >Christoph Schittko [MVP]
> >Software Architect, .NET Mentor
> >
> >"xmlguy" <xmlguy@yahoo.com> wrote in message
> >news:0a1001c38f80$ab042fb0$a001280a@phx.gbl...
> >> XmlTextReader myXmlReader = new XmlTextReader(args[0]);
> >> string en = myXmlReader.Encoding.EncodingName;
> >> //Console.WriteLine(x);
> >>
> >> Error:
> >>
> >> Unhandled Exception: System.NullReferenceException:
> Object
> >> reference not set to
> >> an instance of an object.
> >>
> >> HOW CAN I GET THE ENCODING NAME ? Basically determine
> the
> >> encoding type.
> >>
> >> Also How can I "set" an application wide Encoding ? I
> want
> >> all modules and everything to stick to and conform to
> UTF-
> >> 8.
> >>
> >> But somehow some methods automatically go to UTF-16
> >
> >
> >.
> >


0
10/15/2003 1:43:07 AM
Reply:

Similar Artilces:

setting up new outlook mail account
i can not set up a new account on my outlook, i keep saying establish network connection with a correct sign but searching for my mail account shows X can you please advise Are you trying to setup a POP3 mail account or an Exchange account? Also, what version of Outlook are you using? "rashid" <rashid@discussions.microsoft.com> wrote in message news:C59D04C0-C1C9-4BD1-AE00-2009D25B221D@microsoft.com... > i can not set up a new account on my outlook, i keep saying establish > network > connection with a correct sign but searching for my mail account shows X > ...

How do I set up an argument which asks for multiple criteria
I am trying to use an argument that asks for one of three criteria (2345P, 8319T, or 7026J) in cell C108, and if it finds it, enters the amount of yet another cell, G108 into cell K108, and if not enters 0 into cell K108. It seems there are too many arguments for the "if" argument, and I can't seem to get the "lookup" argument to work either. Is there another argument I should be working with? Thanks -- Diver Try: =IF(OR(C108="8319T",C108="2345P",C108="7026J"),G108,0) "bj" wrote: > try in K108 > =if(or(c108=&qu...

Email sent from iphone not formatted to read in entourage
For starters, I'm using a new macbook pro, and entourage 2008 - via an exchange server environment I just noticed that I can read sent email from entourage formatted just as it was when it was sent (the good news). However, when I send an email from my iphone, the sent folder in entourage displays the sent mail, but formats it in a manner that's not readable (more like code) - in the sent folder, it shows no recipient and no subject. Enclosures are also not showing up in the sent folder On 1/27/10 4:28 PM, Tim Bradbury wrote: > For starters, I'm using a new mac...

OWA Set Rule problem
I have successfully install the Exchange 2003 with SP1 in the Windows Server 2003. Anything alright exclude the rules function in OWA. I try to set the rules from any then "move to" or "copy to" specify folder are no problem, but "forward to" other email address, its don't work. I try to input the email address in the contact and then select from the contact, but the result also don't work. The rules can save and I can receive the incoming email in the Exchange 2003/Outlook or OWA, but it don't forward to my specify email address. I try to...

How do I set the 'Set Synchronizing Client' field
We have a number of outlook clients using CRM that have the 'Set Synchronizing Client' select box greyed out. We need to tick them so that they are able to synchronize tasks etc. Can any one help me find out why these are greyed out and then set them so that they can synchronize thanks In my experience, that checkbox is always greyed out for the first install that is performed for a user. The only time that checkbox becomes active is if a second copy of CRM is installed for a user who already has CRM installed on another PC.... Normally the box is checked and grey. If that is...

How to keep the application even when show desktop is selected
Hi, I am developing an application which is a sort of reminder of your daily tasks. I want this application to remain on the top right corner of desktop even when "show desktop" is selected. However it gets minimised.........Any helps appreciated. Perhaps you want to consider "Active Channel Technology" and making your display part of the "Active Desktop"? In article <D580FA88-9C89-4D3F-AB9A-8374A9DE266B@microsoft.com>, Katiyar@discussions.microsoft.com says... > Hi, > I am developing an application which is a sort of reminder of your dail...

Text and ranges.
How do you wrap text within a range? Hi not really sure what you're trying to do. Could you give an example? -- Regards Frank Kabel Frankfurt, Germany "jim252627" <jim252627@discussions.microsoft.com> schrieb im Newsbeitrag news:4D206631-71FA-48BE-82B4-3624D58A987D@microsoft.com... > How do you wrap text within a range? For example, if I am designing a form and one of the fields of the form requires text, the command would be "wrap-text" within the cell format command. However, if many columns are narrow because of fields (ranges) established above or ...

Formating text of x-axix value
I make a chart with x-axix values from let's say 1E-9 to 1E-3, using logaritmic scale. So far so good. But my need is not to display the values in the chart like 1E-9, 1E-8, etc. but like 10-9, where the -9 text will be formated as upper index. Thx for any help or suggestion. see http://www.stfx.ca/people/bliengme/ExcelTips/Exponents_in_Cells_and_Charts.htm best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "Karel" <Karel@discussions.microsoft.com> wrote in message news:DA5042AE-A412-4CB3-B823-89741DAF8FFD@microsoft.com... >I mak...

How to set backcolour
Hello All I have a continuous form containing a number field (long integer) called [v_colour]. This field contains the number of a certain colour - as per the numbers that are used in the format properties for back colour etc. I would like to set the back colour for the form's [v_colour] text box to be the value of the field: e.g. If the value of [v_colour] in the first record is 255, I want the back colour of the textbox for that record to be bright red. I tried this as the OnLoad event for the form: [v_colour].backcolour = [v_colour].value .... but this resulted in the back colour of...

Conditional Formatting: > and < a date
I am trying to use this forumla as a Conditional Format =0<DAY(D17-NOW())<=10 It does not work. If I remove the 0< or <=10, it will work. Any suggestions? =AND(0<DAY(D17-NOW()),DAY(D17-NOW())<=10) "Brad P" <bradp_xx@hotmail.com> wrote in message news:ftd89m$q0u$1@news.datemas.de... >I am trying to use this forumla as a Conditional Format > > =0<DAY(D17-NOW())<=10 > > It does not work. If I remove the 0< or <=10, it will work. Any > suggestions? > Excellent, thanks for that! "GerryGerry" <Gerry@Ger...

Applying Percent Decrease Across Set Periods
I have a column which includes dates when items were purchased. I have used the DATEDIF function to find the number of years between that date and today's date. I now want to decrease the purchase amount 10% for every year calculated via the DATEDIF function. Any ideas, is this possible, why can't I think...? -- Hunt&amp;Peck ------------------------------------------------------------------------ Hunt&amp;Peck's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=32961 View this thread: http://www.excelforum.com/showthread.php?threadid=527873 ...

Interactive Guide getting "Not a valid Win32 application" error
I downloaded the Interactive Access 2003 to 2007 command reference guide and when I try to run it, I get a "Not a valid Win32 application" error. I've downloaded other interactive guides and had no problem. Help! ...

File format specification
Can anybody please recommend a document giving the detail of the ASCII file specification relating to the importation of data into EXCEL from an external application Thank you very much I'm not sure I understand your question. Wouldn't the specification be dependent upon the layout of the text file. And text files could have lots of different formats. Nick wrote: > > Can anybody please recommend a document giving the detail of the ASCII file > specification relating to the importation of data into EXCEL from an > external application > > Thank you very much ...

Set Regional Settings but not Language
Hi I have a multi-language APP en-US, es-ES, it-IT I usually change Languages and Locales by using the CultureInfo to switch Languages System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("es-ES"); My issue is - what if the user wants to View App in english and use the Regional Options on a PC in say Spain ??? If I change the CultureInfo to en-US then they can view APP in English ( English satelite assemblies) but date and numbers will be in US format If I change the CultureInfo to es-ES then date and numbers will be in Spain forma...

Can I use Access 2007 for Professional Application Development?
I am a .NET developer and a group of friends came to me with thisquestion: They want to develop commercial applications targeted for 50or less users using SQL Server as the back end. They want to know ifaccess could be used for this environment because it appears that itis easier to develop using it than using Visual Studio. I know that access 2007 can be use SQL Server but I don't know if youcan develop forms that use stored procedures instead of SQL Statements(for performance) and if the code can be properly protected. Also Iwould like to know if there is any way to implement a custom l...

can't resize a text box basic
I am creating some software flow diagrams. I add a box and try to add some text. I want the text to be on the box but it ends up being really long and I can't figure out how to re-size it. It ends up being too long. It disappears when I go back to working with the box. When I go to text mode then the text box is too long but I can't figure out how to delete it or resize it to fit on my box. Then I go back to the shape mode and the text box disappears. tia, Hello J, Have a look at this post: http://blogs.msdn.com/visio/archive/2006/08/15/694710.aspx If you haven't come a...

Reading Pane Settings
I did a search for an answer to this question and have not found one. If I missed an answer already posted, please direct me to the right place. I have Outlook 2007 and set up the "right" reading pane for my e-mail. Now when I go to my calendar it is set up the same way - calendar on the left (same size as the inbox) and then there is a blank space to the right that is the size of the reading pane/preview. To the right is the to-do bar (which I have no problem with). I don't know why there is a reading/preview pane on the calendar when there is nothing to preview, and I...

Work Hours setting excludes specified hours from Scheduling
I am miffed by this problem. I specify a work hour schedule for a user. When I schedule a CRM User as a Resource for a Service in Scheduling of a Service Activity with Requested Time of ASAP and click Find Available Times, the values for Avilable Times returned are outside of the Work Hours I specified for the user and not within the work hours. When I drill into the Work Hours for this User, the Calendar view shows Cross Day rather than 8:00AM - 5:00PM I speciied for work hours and editing the hours reveal the correct hours in the Work Hours. What gives? Never mind. Figured out w...

Outlook "Arrange By" option does not retain its setting
In outlook 2007, I use a custom view for my inbox, and I have the Group By option checked to"Automatically group according to arrangement." This has been workn flawlessly until today, when I realized Outlook did not like a particular mouse click; perhaps I clicked on the border of two options or some other anomoly that caused the window toflash once. The end result was that my Arrange By option changed to "From" when I had previously set it to "Conversation." Now, whenever I hange it backto "Conversation," leave the inbox and come back, ...

interactive buttons, multiple sets
hi folks I'm sure one of you good folks will save my bacon as usual I have a series of websites, all of which exhibit the same odd behavior with interactive buttons. I have a bunch of buttons in the left margin, each of which pulls up ( lets call it ) a chapter, and in each 'chapter' are a number of related pages. On the top of each page is an imbedded page which has 'page numbers' for all the 'pages' in that chapter. So, it's a grid where the 'vertical' buttons in the left margin and the 'horizontal' buttons at the top comb...

relate Long Integer with Text
How to relate field as Long Integer in one table with another filed as Text in another table? Two tables are from different database and I cannot change field type by modifying table. Thanks "Song Su" <csitnnn@hotmail.com> wrote in message news:OMyhJ4BsHHA.4740@TK2MSFTNGP02.phx.gbl... > How to relate field as Long Integer in one table with another filed as Text > in another table? > > Two tables are from different database and I cannot change field type by > modifying table. > > Thanks > Song Su, SELECT YT1.YourColumn_Integer ,YT2.YourC...

How do I set OOR
I have searched the help menu and have had no luck finding out how to set my outlook 200 to send an OOR (Out of Office Reply) Any assistance would be great If you are in an Exchange environment (ask your administrator if you do notknow) you can set the Out of the Office Assistant which is located under Tools. If you are not in an Exchange environment you can create a rule that replies on all e-mails. The downside of this is that you'll have to have your Outlook open all the time for the rules to process. Make sure you set some exceptions (for instance based on the subject field so ...

format a cell
does anybody know how i can format a cell so that it looks like its raise. thanks in advance. One play to tinker with Either switch-off the gridlines (Tools > Options > View tab > Uncheck gridlines > OK) or press CTRL + A (select entire sheet) then click to Fill color > white Select the cell(s) Click Format > Cells > Border tab Select the thickest solid line in "Style" Click to format either the right & bottom or the left & top borders Select the thinnest solid line in "Style" Click to format the remaining 2 borders Click OK -- Rgds...

Set Focus
I have text box that I input data into and I was wondering if it is possible to set focus to the text box and avoid clicking on the box. I thought the term is Set Focus, but can't find any information or example that would help in doing so. Any help would be appreciated .. PPT 2003. Look at the following page for code to set focus on a text box: http://officeone.mvps.org/vba/activate_shape.html - Chirag PowerShow - View multiple PowerPoint slide shows simultaneously http://officeone.mvps.org/powershow/powershow.html "Phil K" <PhilK@discussions.microsof...

Get external data-formats too
I have a file that gets data from another Excel spreadsheet. I want to have it retain the formatting (ie. indents) that were made on the imported file. Each time I refresh now, it left justifies everything...any ideas Thanks Hi, If your sheet just gets its data with '=Sheet1!A12'-style formulas, I don't think there's any way short of a macro reformatting the data like the old. Obviously, you can manually copy and paste special to get most of what you want, but it didn't sound like that's your situation... jeff >-----Original Message----- >I have a file that ...