|
I am not sure I understand.
objMyDoc is mshtml.IHTMLDocument2 object which I am using to extract the body of the HTML text. This text is saved in the string "innerText". It appears correctly to this point. But when I write this text to a .txt file, the text file contains garbled characters.
|
|
|
|
|
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;
CookiedWebClient wc = new CookiedWebClient();
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 "";
}
|
|
|
|
|
I'm not sure what you are attempting with CookiedWebClient and HTMLDocumentClass. I would suggest you try replacing
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);
by
data = wc.DownloadData("http://www.alarabonline.org");
strHTML = curEncoding.GetString(data);
tw.Write(strHTML);
to see how that works out. I expect it will handle Arabic text well.
I am puzzled by you casting an HTMLDocumentClass to IHTMLDocument2; and by the compiler accepting your objMyDoc.write(strHTML) statement, as write expects an array of BSTR, not a string.
I would suggest you try and solve your functional requirement based on System.Windows.Form.HtmlDocument
|
|
|
|
|
Meneedhelp wrote: but the output file contains weird characters.
And how exactly did you 'see' those characters?
In other words you used something to view that file. What did you use? And how did you validate that that method would display the characters correctly in the first place?
|
|
|
|
|
I opened up the txt file which I am writing into.
The method displays characters correctly for Spanish, Italian, Hindi and Thai when I replace the http link and the encoding.
|
|
|
|
|
From my WinForm application I have a need to call javascript function from a WebBroswer control using something like this:
webBrowser1.Document.InvokeScript("show_line",...);
The show_line function is in javascript and looks like this:
function show_line(points)
{
for(var i=0;i<points.length;i++)
{
}
}
In other words, the parameter points is an array. My questions is how to pass an array of double from C# to javascript using
webBrowser1.Document.InvokeScript("show_line", points);
Thanks!
modified on Wednesday, October 6, 2010 11:33 AM
|
|
|
|
|
I'm trying to figure out how to set up the inside vertical & inside horizontal line to be setup as hairline weight.
That's what I have for now to setup the line for inside vertical and inside horizontal.
cellRange = oSheet.get_Range(oSheet.Cells[excelRow + 2, excelColumn + 3], oSheet.Cells[excelRow + 6, excelColumn + 7]);
cellRange.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous;
cellRange.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous;
Question is how do I set up the line weight to be hairline?
-- Modified Tuesday, October 5, 2010 2:59 PM
|
|
|
|
|
Try Excel.XlLineStyle.xlSlantDashDot;
For a list of supported styles, see here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
The line weight is kinda of too thick. I prefer hairline esp for printing.
|
|
|
|
|
now that I've got it!
I inserted a new statment line (see 2nd line)
cellRange = oSheet.get_Range(oSheet.Cells[excelRow + 2, excelColumn + 3], oSheet.Cells[excelRow + 6, excelColumn + 7]);
cellRange.Borders.Weight = Excel.XlBorderWeight.xlHairline;
cellRange.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous;
cellRange.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous;
|
|
|
|
|
Ok. Thanks for posting the solution.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
using process.start() i opened a .cs file.but i want to set the cursor to a specified line no, is there any way to do this.
thanx in advance.!
|
|
|
|
|
What are you trying to accomplish?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
through my application i want to open the *.cs file in vs2005 and set the cursor to the specified line.
in my application i search a specified text in the given cs file and show the filename and the line no,so i want to allow the user to goto the location of that file opened in vs2005.
|
|
|
|
|
There is already Find functionality in Visual Studio. I don't understand what you are trying to gain or accomplish outside of VS. In any case you would need to use automation and to my knowledge it is not available for execution outside of VS. It sounds like you need to create a Visual Studio Addin rather than an external application.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Interactively, in Visual Studio:
- use menu Edit/GoTo... (or CTRL/G) and type the line number
- when you have an error message in the output pane, double-click it
Programmatically, I don't think there is a way.
[ADDED]
i.e. I am unaware of an API that would support this. You could always try a little automation stuff. I'm not going to elaborate on it, IMO it isn't worth it; however Google knows all about it.
[/ADDED]
|
|
|
|
|
i found a way to open the cs file and navigate to the line i need , it can be done using switches in vs2005.
but there is a limitation , means when the ide is open when you open a file it won't navigate,it can only navigate to the line when the ide is starting up, so need to know if there is any one who knows a solution.
i don't want to open separate ide s for each file.
|
|
|
|
|
You can do it via a Visual Studio Addin. If you'd care to download MoXAML Power Toys (follow the link in my sig), and you can download the source code for an add in that works with source files. There are plenty of samples in there where the code is manipulated via Visual Studio (Note, it's a VS2008 solution, but the code works in VS2005 as well).
|
|
|
|
|
It's built-in, RTFM:
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv" template.vb /command "edit.goto 10"
http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx
(Don't use the /edit switch.)
|
|
|
|
|
Hello!
I want to pass an array of double values into unmanaged C code.
Example:
<code>
[DllImport("DummyDll.DLL")]
public static extern int nCalcAll(double* dpData, int Nx, int Ny);
static void Main(string[] args)
{
Console.WriteLine("Call native dll...");
double[] array = {32 * 32};
int result = nCalcAll(array, 32, 32);
Console.WriteLine("...calc all from c dll");
}
</code>
At the line "int result = nCalcAll(array, 32, 32);" it throws a runtime error.
How can I solve this problem?
I've never dealt with Interop before, so any help would be greatly appreciated.
Thanks!
|
|
|
|
|
What kind of error, exactly?
You may need to specify the calling convention as cdecl, the default is stdcall.
|
|
|
|
|
Thanks for all your help!
It was indeed the Calling Convention. When I set it to CallingConvention.Cdecl, everything runs fine
|
|
|
|
|
Blackwurst wrote: it throws a runtime error
I don't think so, I expect it does not even compile as your function invocation (with array) doesn't match the prototype (with pointer).
Here[^] is all you probably need to know, with array examples and all.
|
|
|
|
|
I assumed the code he posted was not his actual code - there is more in there that just doesn't make sense. That array containing only 1024.0 is definitely suspicious, if the second and third arguments to that function are supposed to be about the width and height of the array.
So, I think he just typed an example here
|
|
|
|