المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Unable to write Arabic text to a text file using C# [modified]



C# Programming
10-06-2010, 01:11 AM
I have a piece of code that reads an Arabic http link and copies the html body text to a text file. While debugging, I can see that the arabic text is being read correctly (I see arabic characters) but the output file contains weird characters. Can someone point out to me what I am doing wrong here? Here is relevant part of the code:

public string GetWebText()
{
byte[] data;
mshtml.HTMLDocumentClass ms;
string strHTML;
mshtml.IHTMLDocument2 objMyDoc;
string innerText;
TextWriter tw;
FileInfo fi;
int count = 0;
Encoding curEncoding = Encoding.GetEncoding(1256);
string htmlEncodingString = null;

******dWebClient wc = new ******dWebClient();

fileName = path + curLangStr +".txt";
FileStream ostrm = new FileStream(fileName, FileMode.Create, FileAccess.Write);
tw = new StreamWriter(ostrm, curEncoding);
int j = 0;
try
{
data = wc.DownloadData("http://www.alarabonline.org");
ms = new mshtml.HTMLDocumentClass();
strHTML = curEncoding.GetString(data);
objMyDoc = (mshtml.IHTMLDocument2)ms;
objMyDoc.write(strHTML);
innerText = objMyDoc.body.innerText;
tw.Write(innerText);
}
}
catch (Exception e)
{
Console.WriteLine("Exception message: " + e.Message +" url["+j+"] : "+urlArray[j]);
}
finally
{
tw.Close();
wc.Dispose();
}

return "";
}
modified on Tuesday, October 5, 2010 5:08 PM