|
|
help me, how to write Listbox in webcontrol, I see ListBoxMultiCol in this but It write for window Form
someone, can help me to do this???
thanks
Ps : what's the protected method to draw Item on ListBox???
Nho'c ti`
|
|
|
|
|
I'm trying to extract links frome a webpage by mshtml.Now I'm eager for help.
The following code can be reffered: (most from .S.Rod)
[ComImport, Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPersistStreamInit
{
IntPtr GetClassID();
void IsDirty();
void Load(IntPtr pStream);
void Save(IntPtr pStream, bool fClearDirty);
long GetSizeMax();
void InitNew();
}
private void LinkExtractor()
{
mshtml.HTMLDocumentClass docCls=new mshtml.HTMLDocumentClass();
IPersistStreamInit pS = (IPersistStreamInit) docCls;
pS.InitNew();
docCls.createElement("<a href='http://www.codeproject.com'>link</a>");
//the following code is to get bodyElement,but failed
int i=0;
for(i=0;i<5;i++)
{
object oIndex=(object)i;
if(i==3)
{
System.Type type=docCls.all.item(oIndex,oIndex).GetType();
mshtml.HTMLBodyClass bodyCls=(mshtml.HTMLBodyClass)docCls.all.item(oIndex,oIndex);
}
}
}
Now I wonder how can I get the bodyElement,by which can easily extract all links of a webpage.
|
|
|
|
|
Hello Benzite,
- if you create a HTMLDocument instance, then it's like an empty web page. Before you can browse the tree of tags, you have to fill the HTMLDocument. That's the reason why you don't find any <body> element.
- to fill the DOM, you could use IPersistFile.Load(filepath), IUrlMoniker(url). Or, may be simpler, something David Stone has pointed out in this forum a couple of days ago : he uses the WebClient class to download the web page and get the source code. Now you can use the web page you have just retrieved and pass it as a parameter to HTMLDocument.write(...).
Good luck!
|
|
|
|
|
Thanks,you have given me a lot of help!
I have use the WebClient class get the webpage's source code. When use HTMLDocument.write(params[] object psarray),I don't know the content of psarray,and how to build psarray from the source code.Can you tell me somthing about psarray.
|
|
|
|
|
My recommendation is to use this code :
using System.Net;
using System.Text;
<p> </p>
mshtml.HTMLDocumentClass doc = new mshtml.HTMLDocumentClass();
IPersistStreamInit pS = (IPersistStreamInit) doc;
pS.InitNew();
WebClient client = new WebClient();
byte[] data = client.DownloadData("http://www.microsoft.com");
doc.body.innerHTML = ASCIIEncoding.ASCII.GetString(data);
|
|
|
|
|
Wonderful! The body element has been built.
Can you tell me the reason use the following sentence?
IPersistStreamInit pS = (IPersistStreamInit) doc;
thanks.
|
|
|
|
|
It's COM's queryinterface. Since doc is a IHTMLDocument2 interface, the only way to be able to call a IPersistStreamInit interface method is to query for the interface first, and then call the method. In C#, queryinterface is just a cast, hence the (IPersistStreamInit) . (the CLR manages the underlying COM queryinterface).
|
|
|
|
|
thanks
|
|
|
|
|
benzite wrote:
Now I wonder how can I get the bodyElement,by which can easily extract all links of a webpage.
To extract all links, you only need to access the anchors collection : docCls.anchors.length , docCls.anchors.item(i) .
|
|
|
|
|
You now how in HTML you can make a link and outlook automaticly opens with that address in the send box and all of that....
<mailto="eggie5@techline.com">
Or how ever that goes... you get my idea right?
Well, what is the equivlant of that, in C#...
So, how would I open up outlook by clicking on a link from a C# form?
/\ |_ E X E GG
|
|
|
|
|
1) Put a LinkLabel on your form.
2) Make a Click event for your LinkLabel.
3) In the LinkLabel click event, put this code:
System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"commandline");
where commandline is the commandline, which can be things like:
"C:\Program Files\Outlook Express\msimn.exe" to launch Outlook Express, or
"mailto:forum@codeproject.com" or whatever the email address is, to launch your default email program with a new email to that address.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I wanted to build a page all in code behind so that I could learn how this is done in C#. So I tried by developing below and calling from an aspx page. It compiles fine but I just get a blank page. Does anyone have any thoughts on what is wrong?
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class myPage: Page
{
public System.Web.UI.WebControls.TextBox txtTextBox;
public System.Web.UI.WebControls.Label lblLabel;
public void CreateChildControls(HtmlTextWriter stringWriter)
{
// Use htmlWriter to write HTML.
string strOpenHTML;
strOpenHTML = "<title>My Page";
strOpenHTML += "Enter some text:";
this.Controls.Add( new LiteralControl( strOpenHTML ) );
// Add HTMLForm Tag
HtmlForm frmForm = new HtmlForm();
frmForm.ID = "myForm";
Controls.Add( frmForm );
// Add a TextBox
txtTextBox.ID = "myTextBox";
frmForm.Controls.Add( txtTextBox );
// Add a Button
Button btnButton = new Button();
btnButton.Text = "Click Here!";
//AddHandler btnButton.Click, AddressOf Button_Click;
btnButton.Click += new EventHandler(Button_Click);
frmForm.Controls.Add( btnButton );
btnButton.Text = "Click Here!";
frmForm.Controls.Add( btnButton );
// Add Page Break
frmForm.Controls.Add( new LiteralControl( "" ) );
// Add a Label
lblLabel.ID = "myLabel";
frmForm.Controls.Add( lblLabel );
// Add Closing HTML Tags
string strCloseHTML;
strCloseHTML = "";
Controls.Add( new LiteralControl( strCloseHTML ) );
}
void Button_Click( object s, EventArgs e )
{
lblLabel.Text = txtTextBox.Text;
}
}
Code to Live Live to Code
|
|
|
|
|
I have a web form that uses a WebRequest object in order to get the binary content from an .aspx
so the .aspx makes a Response.BinaryWrite and outputs a bunch of bytes
however I have the following code
WebRequest request = WebRequest.Create(serverRequest);
WebResponse response = request.GetResponse();
if (response.ContentLength > 0)
{
using (FileStream fs = new FileStream
(filePath,FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[response.ContentLength];
response.GetResponseStream().Read(buffer, 0,
buffer.Length);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
when the file is saved, the size of the file is correct, however the content is not, most of the bytes dont arrive
anybody has any idea about why?
the .aspx outputs sometimes 2.5 MB, im not sure if size is causing the problem
Basically the idea of what I'm trying to do is get the binary response from an .aspx from a winform, and then save it in a file
Thanks
|
|
|
|
|
Try changing the MIME ContentType of the output stream in the aspx page.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
I have a network stream that I am reading from, and I read from it one byte at a time (i.e., as opposed to using a stream reader or requesting a whole block). I set the receive buffer size directly on the associated TcpClient to be fairly large (i.e., ReceiveBufferSize = 250k).
My question: Since I already have a buffer on the socket and I am reading one byte at a time, is there a benefit to wrapping my network stream with a buffered stream?
|
|
|
|
|
Does anyone know of an IHTMLEditHost sample for C#? The only one I can find is in C++ w/ATL. If someone can tell me where to find one in C#, it would save me alot of time.
So you know what I'm talking about, here's the C++/ATL sample[^].
TIA ,
J Dunlap
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
These interfaces are part of the Microsoft.Mshtml.dll PIA. (c:\program files\Microsoft.NET\Primary interop assemblies). And are available at run-time with IE5.5+ browsers.
You could build the type-library by recompiling the mshtml.idl file frm the Platform SDK, and then import it with tlbimp.
|
|
|
|
|
.S.Rod. wrote:
You could build the type-library by recompiling the mshtml.idl file frm the Platform SDK, and then import it with tlbimp.
I've done the former but not the latter, and I will do the latter soon. What I was looking for was basically a sample to help me along. I've read the docs and have a fairly good understanding (and it helps that I've dealt with the HTML object model on web pages), but a sample would help.
|
|
|
|
|
If i have a web server with several IPs, then how can I determine the IP number of the server in my code? Can it be determined in a C# dll, or does it have to be determined in ASP .Net and then passed down? Either way, how do I get the IP.
Thanks.
|
|
|
|
|
Request.ServerVariables("LOCAL_ADDR") have not tried but I don't see any reason why this will not work
Meg Rules
|
|
|
|
|
It gave me an IP number but not one of my machine. Got some default IP number.
|
|
|
|
|
Ok, It worked. In my IIS setup I had IP as usnassigned. Once I assign an IP the ServerVariables property works.
Thanks.
|
|
|
|
|
|
That works too. But how about this. Is there a way to get this information in a DLL, i.e., the Request object is available in ASP. Lets say the code behind calls a C# DLL to do some stuff. Is there a way to get the IP in the DLL. I dont want to pass the number around. I could save it, but what I am looking for is if there is actually an API for it.
Thanks
|
|
|
|