|
It is usually inappropriate to write text (html) at the byte level. This is because modern unicode strings do not have a simple 1 byte = 1 character mapping.
What is probably happening is that the file you are reading from is in one text encoding (e.g. UTF8), and the file you are writing to is in another (e.g. ASCII).
Just read and write strings, and you should be fine. It may help to educate yourself on text encodings first though.
One of the better articles on this subject is from Joel on Software.
my blog
|
|
|
|
|
Steven's right, but what you need to do is actually quite easy.
Wrap your FileStream (or whatever Stream derivative you're using) in a StreamReader or StreamWriter , which makes reading and writing text much easier. You can specify the encoding (like Encoding.Unicode, since you're probably dealing with Unicode characters on the 'net, or UTF8 which is most common (a multi-byte character set, or MBCS)) and with the <code>StreamReader you can set a parameter in the constructor that attempts to detect the encoding by detecting a byte-order mark (BOM).
For example:
using (FileStream file = File.Open("somefile.html", FileMode.Open))
{
string line = null;
using (StreamReader reader = new StreamReader(file, Encoding.UTF8, true))
{
line = reader.ReadLine();
}
} The using blocks make sure the streams are closed (i.e., the native file handles are released - very important or your performance is hampered, or - worse yet - you have memory leaks).
You should really read about the Encoding class in the .NET Framework SDK. You could still read and write bytes but you must understand that ANSI is a single-byte character set, and may use different code pages. ASCII characters use only 7 bits in the byte (the first 128 values). The last 128 values can be different depending on the codepage (local characters, or defined for particular systems). UTF8 can handle ASCII characters, but those latter characters actually tell the decoder to use 2 bytes to read the character, thus supporting Unicode as well. This is a great encoding to use on legacy systems, especially if you're not sure what a text file will contain (although a legacy decore might have problems). Unicode comes in many flavors, and you can read more on the web if you try a google search or click "Search comments" above for previous discussions we've had about this.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi! Thanks alot! Both to Heath and Steven!
Will try this first thing monday morning!
The Joel on Software text gave som intresting, and fun!, reading.
/ Mikke
|
|
|
|
|
Hi,
Im writing a component for posting data to a webserver.
http://www.domainname.com/fire/incoming.asp?user=xxxx&pass=xxxx&amount
I tried using HttpWebrequest & Webclient to post data but it is returning an error
if i paste the url in the browser it is working properly
The code goes here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string User = "test3";
string Pass = "test3";
string amount = Server.UrlEncode(TextBox2.Text);
string MobileNumber = "91"+TextBox1.Text;
string postData = ("login="+User);
postData += ("&pass="+Pass);
postData += ("&amount="+amount);
string uriString = "http://www.domainname.com/fire/incoming.asp";
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
lblStatus.Text = Encoding.ASCII.GetString(responseArray);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can someone help .....
Thanks in advance
Abraham
|
|
|
|
|
I want to do a maskedit control that it like powerbuilder or delphi's maskedit
control.
|
|
|
|
|
Great...what's your question?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi all,
I would like to program in c# a graphical design tool like ms visio. I need the functionalities of component inserting, deleting, resizing, moving, component connecting and so on. Someone knows sample codes or tutorials?
Thx
|
|
|
|
|
I would say that is more of an OO thing than an algorithmic thing.
For example, you have two classes called DrawingSurface and Component .
DrawingSurface has a collection of Component s
To Insert you instantiate a component (Component theComponent = new Component() ) and add it to the DrawingSurface (DrawingSurface.Add(theComponent); )
To Delete to remove the component from the DrawingSurface (DrawingSurface.Remove(theComponent); )
To Resize you would have properties on the component like Width and Height . You might trigger an event on the setters of these properties that the DrawingSurface would handle to redraw the diagram.
To Move you would have position properties on the component like X and Y . And again in the setters you would probably fire off an event that the drawing surface uses to redraw the display.
And so on and so forth.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
I've tried to create a custom progressbar to display while I'm doing some intensive work. I also want to update a string of what is currently going on, like an installer tells the user what file is currently being copied, and so on...
So, I have a form that I display and then call methods like
<br />
MyProgressForm.setProgressText(string)<br />
MyProgressForm.setProgress(int)<br />
but the GUI components (a label for the text and a custom-painted control for the progress) won't get updated, I guess because there is too much work going on...
So my question is, how do I force these to be updated?
What is the best way to solve this?
thankful for some help, I can't seem to figure it out ...
|
|
|
|
|
Calling the Update method of your ProgressBar after changing its Value or Text should solve the problem.
www.troschuetz.de
|
|
|
|
|
You should be doing the lengthy processor intensive work in a thread seperate from the main gui thread. Start a worker thread and do your lengthy work there. Update the progress bar's values from the worker thread. The main window thread will then keep your bar painted properly.
|
|
|
|
|
Hi
I am searching for a correl function like the one i can use in excel with =CORREL(A1:A10;B1:B10).
Nothing complicated I will just know the correlation of two arrays.
I have googled but wasn't successful. Maybe somebody have a hint where to search.
Thanks
|
|
|
|
|
|
Im posting some data to this URL.
Can someone tell me where i can post data to this url like this.
string uriString = "http://domainname.com/incoming.asp";
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
(or )
do we need to post only to
string uriString = "http://domainname.com/";
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
Can anyone help me how to go about this?
Abraham
|
|
|
|
|
in DataGrid of WinForm Use C#?
thanks!!
|
|
|
|
|
hi,
Check this site for your queary.
www.datagridgirl.com
Section head : article
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi skywen,
When you are using Datagrid control on winforms by default it allows you to add, delete , update rows during the runtime. If you are using a Data grid webserver control you need to use footer template to create this functionality.
Thanks
SGS
|
|
|
|
|
One suggestion i found was to extend System.ComponentModel.Component
My problem is that thing doesnt have paint or other necessary visual functions. Any other ways?
...My situation is a control that is like a tooltip not dedication to the form but considers the desktop as it's parent... what it boils down to is i want to make it a component tray restricted control, but give it a custom UI editor so someone can view changes to the control.
|
|
|
|
|
Hi all,
I'm hoping someone can point me in the right direction.
I would like to write a server application that takes data from various elements within a network. These are UNIX based systems which basically will be spitting alarming information at m at a billion miles an hour. Consequently, I'm establish communications with the sending devices. I only want to receive the information they are throwing at me. I don't need to be concerned with the format of the data.
Has anyone suggestions on how best to implement a server type application to recieve the data from 10+ uniques device elements without having to establish a link first. All devices output on the same port number as well to throw in another problem.
Any advice, suggestions would be most appreciated.
Thanks,
Aaron
|
|
|
|
|
I think if you know that simultaneous clients to your server would not exceed 10 you can implement this with a TCP or UDP listener. On each new connection request, spawn a new thread for receiving data. After completion close the socket and thread.
If your number of simultaneous clients are going to exceed that 10, you can think about asynchronous connections.
See socket/tcplistener/udplistener classes and examples in MSDN.
|
|
|
|
|
Sorry - I might have been a bit vague - the data is coming from UNIX clients....
The data is transmitted over a network to an IP I can specify. It will just spit data over a UDP connection to where ever I tell it, but it is not controlled.
I guess what I need is a UDP listener.... hmm
|
|
|
|
|
Check out some of the socket example here in the networking section for C#. You will basically need to set up an asynchronous socket listener on the port # you want the UNIX clients to send messages to. It's a good thing they all send on the same port as that means you will only need to listen on one.
In addition you'll need to format your application level messages to make sure you get a whole message before doing something with it. I suspect your UNIX clients will terminate each individual transmission with some sort of control character. So on your end you'll need to receive until you read in that control char.
Hope this helps!
|
|
|
|
|
How do you create a multicolumn listbox with comboBox's within the columns? I am looking for a control that is similar to one such as the design editor in Microsoft Access or Enterprise Manager. Is there a built in control already created for this?
While using "Spy++" these controls have been called "OGrid" and "DimensionDataCtrl". I am been unable to find a library/assembly with either of these controls.
Thanks.
|
|
|
|
|
hi,
I can suggest you an article which deal these sort of customization.
http://www.codeproject.com/cs/miscctrl/ListViewCellEditors.asp
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
There is probably a very simple reason for this.
I wrote a simple application for a simple assignment. I am having a problem understanding how doubles are subtracted. Here is a code sample:
<br />
double paid = 50.00, owed = 39.67, remainder = 0.0; <br />
remainder = paid - owed;<br />
<br />
Console.Write(remainder);<br />
Console.ReadLine();<br />
This results in a value of 10.33 being printed to the screen. However, if you step into the program you will see that remainder is actually equal to 10.329999999999998.
Can anyone explain to me how C# comes up with this value?
Thanks in advance for your help!
|
|
|
|