I'm trying to read an excel sheet and displaying contents to console. the code is here    FileStream fileStream = new FileStream(@"E:\USERS\MyWorkbook.xlsx", FileMode.Open, FileAccess.Read);   byte[] byteCode = new byte[fileStream.Length];   fileStream.Read(byteCode, 0, (int)fileStream.Length);               foreach (var byteValue in byteCode)   {       Console.Write(Convert.ToChar(byteValue));   }   Console.ReadLine();   the output is     PK♥♦¶ ♠   ! bî?h^☺  ?♦  ‼☻[Content_Types].xml ¢♦☻(  ☻      ¬?ENA0►E÷HüCä-JÜ²5í?Ç↕*Q>AÄ?Æªc[?iiÿ??û►B¡§j7±↕IÜ{2ñIh²nm¶??Æ»R♀??EAU^←7/>ÅÇ   ì%¿↨↓?rZYï ¶←@1↓__?f? ?q·AR4DáAJ¬→h§▬>?a?UÇV◄ßÆ1♀ªZ"9EUAàNV_◄8EcO►aÑ‼Oji){^óa-I♦   ?"{Ü▬v^¥P!XS)bR1rú?K_s(,3O`▬_§ïßeÖ↔♦»ß1æ►@(?a?sí?►[í?☼öB·LA?F←I↔"fKlk↑--¿$♣?A   pN$å   What's wrong with it?
39815
Is there a free or open source library to read Excel files (.xls) directly from a C# program?   It does not need to be too fancy, just to select a worksheet and read the data as strings. So far, I've been using Export to Unicode text function of Excel, and parsing the resulting (tab-delimited) file, but I'd like to eliminate the manual step.
96947
I got an e-book reader a few months ago, and I finally figured out why it doesn't display .txt files correctly. It doesn't like ANSI. It has no problem with the other 3 types of coding notepad provides.    For a reason I chose UTF-8 and decoded all the .txt files I have on it (we are talking thousands of small but important documents). They work correctly and now I pay attention to save in UTF-8, but I know myself, I know that at some point I will forget it, and save in the default ANSI.  So the question after the small novel: Is there any way to change the default coding when saving a newly opened notepad? (Win 7)    I know about the way to change the default when opening a previously created .txt file but it's a pain to always create the new document first.
75487
VB has a couple of native functions for converting a char to an ASCII value and vice versa  - Asc() and Chr().  Now I need to get the equivalent functionality in C#.  What's the best way?
56439
In a J2EE application (like one running in WebSphere), when I use System.out.println(), my text goes to standard out, which is mapped to a file by the WebSphere admin console.  In an ASP.NET application (like one running in IIS), where does the output of Console.WriteLine() go?  The IIS process must have a stdin, stdout and stderr; but is stdout mapped to the Windows version of /dev/null or am I missing a key concept here?  I'm not asking if I should log there (I use log4net), but where does the output go?  My best info came from this  where they say Console.SetOut() can change the TextWriter, but it still didn't answer the question on what the initial value of the Console is, or how to set it in config/outside of runtime code.
11465
I created an ASMX file with a code behind file. It's working fine, but it is outputting XML.  However, I need it to output JSON. The ResponseFormat configuration doesn't seem to work. My code-behind is:  [System.Web.Script.Services.ScriptService] public class _default : System.Web.Services.WebService {     [WebMethod]     [ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)]     public string[] UserDetails()     {         return new string[] { "abc", "def" };     } }
4360
I have a console application project in C# 2.0 that needs to write something to the screen in a while loop. I do not want the screen to scroll because using Console.Write or Console.Writeline method will keep displaying text on console screen incremently and thus it starts scrolling.  I want to have the string written at the same position. How can i do this?  Thanks
22890
In Java, I have a String and I want to encode it as a byte array (in UTF8, or some other encoding). Alternately, I have a byte array (in some known encoding) and I want to convert it into a Java String. How do I do these conversions?
100063
I need to stream a file to the Response for saving on the end user's machine.  The file is plain text, so what content type can I use to prevent the text being displayed in the browser?
114316
I'm trying to read an Excel file (Office 2003). There is an Excel file that needs to be uploaded and its contents parsed.  Via Google, I can only find answers to these related (and insufficient topics): generating Excel files, reading Excel XML files, reading Excel CSV files, or incomplete abandoned projects. I own Office 2003 so if I need any files from there, they are available. It's installed on my box but isn't and can't be installed on my shared host.  Edit: so far all answers point to  and/or  about how to use it.
84866
I wanted to use fstream to read a txt file.  I am using inFile &gt;&gt; characterToConvert, but the problem is that this omits any spaces and newline.  I am writing an encryption program so I need to include the spaces and newlines.  What would be the proper way to go about accomplishing this?
69113
I am working on a project right now that involves receiving a message from another application, formatting the contents of that message, and sending it to a printer.  The technology of choice is C# windows service.  The output could be called a report, I suppose, but a reporting engine is not necessary.  A simple templating engine, like StringTemplate, or even XSLT outputting HTML would be fine.  The problem I'm having is finding a free way to print this kind of output from a service.  Since it seems that it will work, I'm working on a prototype using Microsoft's RDLC, populating a local report and then rendering it as an image to a memory stream, which I will then print.  Issues with that are:   Multi-page printing will be a big headache. Still have to use PrintDocument to print the memory stream, which is unsupported in a Windows Service (though it may work - haven't gotten that far with the prototype yet) If the data coming across changes, I have to change the dataset and the class that the data is being deserialized into.  bad bad bad.   Has anyone had to do anything remotely like this?  Any advice?  I already posted a question about printing HTML without user input, and after wasting about 3 days on that, I have come to the conclusion that it cannot be done, at least not with any freely available tool.  All help is appreciated.  EDIT: We are on version 2.0 of the .NET framework.
32831
If you have a java.io.InputStream object, how should you process that object and produce a String?    Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for example I can write that to a log file.  What is the easiest way to take the InputStream and convert it to a String?  public String convertStreamToString(InputStream is) {     // ??? }
120955
I am creating a lightweight editor in C# and would like to know the best method for converting a string into a nicely formatted XML string.  I would hope that there's a public method in the C# library like "public bool FormatAsXml(string text, out string formattedXmlText)", but it couldn't be that easy, could it?  Very specifically, what would the method "SomeMethod" have to be that would produce the output below?  string unformattedXml; string formattedXml;  unformattedXml = "&lt;?xml version=\"1.0\"?&gt;&lt;book&gt;&lt;author&gt;Lewis, C.S.&lt;/author&gt;&lt;title&gt;The Four Loves&lt;/title&gt;&lt;/book&gt;" formattedXml = SomeMethod(unformattedXml);  Console.WriteLine(formattedXml);   Output:  &lt;?xml version="1.0"?&gt;   &lt;book id="123"&gt;     &lt;author&gt;Lewis, C.S.&lt;/author&gt;     &lt;title&gt;The Four Loves&lt;/title&gt;   &lt;/book&gt;
20412
I was looking for a generic method in .Net to encode a string for use in an Xml element or attribute, and was surprised when I didn't immediately find one.  So, before I go too much further, could I just be missing the built-in function?    Assuming for a moment that it really doesn't exist, I'm putting together my own generic EncodeForXml(string data) method, and I'm thinking about the best way to do this.    The data I'm using that prompted this whole thing could contain bad characters like &amp;, &lt;, &quot;, etc.  It could also contains on occasion the properly escaped entities: &amp;amp;, &amp;lt;, and &amp;quot;, which means just using a CDATA section may not be the best idea.  That seems kinda klunky anyay; I'd much rather end up with a nice string value that can be used directly in the xml.  I've used a regular expression in the past to just catch bad ampersands, and I'm thinking of using it to catch them in this case as well as the first step, and then doing a simple replace for other characters.    So, could this be optimized further without making it too complex, and is there anything I'm missing? :  Function EncodeForXml(ByVal data As String) As String     Static badAmpersand As new Regex("&amp;(?![a-zA-Z]{2,6};|#[0-9]{2,4};)")      data = badAmpersand.Replace(data, "&amp;amp;")      return data.Replace("&lt;", "&amp;lt;").Replace("""", "&amp;quot;").Replace("&gt;", "gt;") End Function   Sorry for all you C# -only folks-- I don't really care which language I use, but I wanted to make the Regex static and you can't do that in C# without declaring it outside the method, so this will be VB.Net  Finally, we're still on .Net 2.0 where I work, but if someone could take the final product and turn it into an extension method for the string class, that'd be pretty cool too.  Update The first few responses indicate that .Net does indeed have built-in ways of doing this.  But now that I've started, I kind of want to finish my EncodeForXml() method just for the fun of it, so I'm still looking for ideas for improvement.  Notably: a more complete list of characters that should be encoded as entities (perhaps stored in a list/map), and something that gets better performance than doing a .Replace() on immutable strings in serial.
87083
Here's the problem:  In C# I'm getting information from a legacy ACCESS database. .NET converts the content of the database (in the case of this problem a string) to Unicode before handing the content to me.  How do I convert this Unicode string back to it's ASCII equivalent?   Edit Unicode char 710 is indeed MODIFIER LETTER CIRCUMFLEX ACCENT. Here's the problem a bit more precise:     -> (Extended) ASCII character ê (Extended ASCII 136) was inserted in the database.  -> Either Access or the reading component in .NET converted this to U+02C6 U+0065     (MODIFIER LETTER CIRCUMFLEX ACCENT + LATIN SMALL LETTER E)  -> I need the (Extended) ASCII character 136 back.    Here's what I've tried (I see now why this did not work...):  string myInput = Convert.ToString(Convert.ToChar(710)); byte[] asBytes = Encoding.ASCII.GetBytes(myInput);   But this does not result in 94 but a byte with value 63... Here's a new try but it still does not work:  byte[] bytes = Encoding.ASCII.GetBytes("ê");    Soltution Thanks to both  and  for pointing in the right direction I solved the problem .
64302
I frequently find myself writing code like this:  List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 5 }; foreach (int i in list) {     Console.Write("{0}\t", i.ToString()); } Console.WriteLine();   Better would be something like this:  List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 5 }; Console.WriteLine("{0}\t", list);   I suspect there's some clever way of doing this, but I don't see it. Does anybody have a better solution than the first block?
35988
I am programmatically exporting data (using PHP 5.2) into a .csv test file. Example data:   Numéro 1 (note the accented e). The data is utf-8 (no prepended BOM).  When I open this file in MS Excel is displays as NumÃ©ro 1.  I am able to open this in a text editor (UltraEdit) which displays it correctly.  UE reports the character is decimal 233.  How can I export text data in a .csv file so that MS Excel will correctly render it, preferably without forcing the use of the import wizard, or non-default wizard settings?