I Seem to be unable to read HTML after a WPF web browser control has finished navigating to a page.
The reason I have to use a WebBrowser instead of a HttpClient, is because the required web page requires logging into first.
XAML:
<WebBrowser x:Name="wbBrowse" Source="anywebpage" LoadCompleted="wbBrowse_LoadCompleted">
</WebBrowser>
Code:
private void wbBrowse_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
var doc = wbBrowse.Document;
}
I've tried casting Document to HtmlDocument but it crashes. It's a '{System.__ComObject}' object which means nothing to me.
Thanks
Add a reference to Microsoft HTML Object Library under Project->Add Reference->COM in Visual Studio and cast the value of Document to an MSHTML.IHTMLDocument2:
private void wbBrowse_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MSHTML.IHTMLDocument2 doc = wbBrowse.Document as MSHTML.IHTMLDocument2;
...
}
This does work in .NET Core 3.1.
Related
I am working on Kinect project for Blob detection using Kinect sdk 2.0.
After doing so much efforts to find reference tutorial for it, I found out following tutorial.
http://blogs.claritycon.com/blog/2012/11/blob-tracking-kinect-opencv-wpf/
The issue is that this example is built on Kinect sdk 1.8 . Because of that, some events and methods which are not supported in kinect sdk 2.0.
for eg.
private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
(Error:The type or namespace name AllFramesReadyEventArgs could not be found(are you missing a using directive or an assembley reference?))
I tried to find out those events and methods new name for kinect sdk 2.0 but I didn't get anything.
You can use a different frame callback that listens to MultiSourceFrameReader. This can receive BodyFrameType, DepthFrameType, ColorFrameType, etc. simultaneously.
For example:
private void Reader_FrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) {
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame().BodyFrameReference.AcquireFrame()) {
// do something
}
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame().DepthFrameReference.AcquireFrame()) {
// do something
}
}
To add a frame to this callback, instantiate a MultiSourceFrameReader reader object and do this:
this.reader.MultiSourceFrameArrived += Reader_FrameArrived;
we have been running an ASP .NET (without MVC) application for years without any problems. However, we have now changed the server and now we get the following error:
OutputStream is not available when a custom TextWriter is used.
Exception Details: System.Web.HttpException: OutputStream is not available when a custom TextWriter is used.
Stack Trace:
[HttpException (0x80004005): OutputStream is not available when a custom TextWriter is used.]
System.Web.HttpResponse.BinaryWrite(Byte[] buffer) +4840090
App.Loader.Page_Load(Object sender, EventArgs e) +3464
See my code below:
public partial class Loader : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
var filePath = #"C:\test\testfile.jpg";
Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(File.ReadAllBytes(filePath));
Response.End();
}
}
I have noticted that the error occurs as soon as the property OutputStream from Response object is accessed.
I have found a lot of similar problems here and in the web but I am afraid those are always in an context of an mvc application.
Thank you very much in advance!
I have found the solution now.
I am running the cms system umbraco with this application and its new version uses the MVC framework as underlying framework. Therefore, I suppose that the Response object was somehow not valid any more.
I want create a very simple HTML parser application. I read lots of tutorial and lots of developer use this class: HtmlDocument.
I want use this class in my app too but I am not able to add reference to System.Windows.Forms.
I try to add reference in Project > Reference but I can't find Windows.Forms.
How can I fix this problem and use HtmlDocument?
I use Visual Studio 2013.
Thank you.
This is my very simple code:
namespace ParseHTML
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
string url = "http://www.alvolante.it/";
download(url);
}
private async void download(string url)
{
HttpClient client = new HttpClient();
string risposta = await client.GetStringAsync(new Uri(url)); //download html della pagina web
HtmlDocument hc = new HtmlDocument(); //error here, missing reference or assembly?
}
You can't. WinForms is not supported nor even implemented on Windows Phone (Windows Mobile 6.5.3 released in early 2010 is the last "Windows" phone OS to support WinForms by way of the Compact Framework).
To process HTML in applications, I suggest HtmlAgilityPack instead, which provides a fault-tolerant DOM manipulation library: http://htmlagilitypack.codeplex.com
I found the similar questions how to call java script function from activex or dll in c# but this is not provide me solution.than i continue my searching finally i got msdn link on this
http://msdn.microsoft.com/en-us/library/ms171712.aspx
To access DOM from a UserControl hosted in Internet Explorer
Create your own custom derived class of the UserControl class. For more information, see How to: Author Composite Controls.
Place the following code inside of your Load event handler for your UserControl:
HtmlDocument doc = null;
private void UserControl1_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}
Unfortunately I am still unable to get DOM object in my class.I have try to see what i get in this.Site so i put it on a messagebox
MessageBox.Show(this.Site.ToString());
which shows me strange thing that is
System.Windows.Forms.Control+AxSourcingSite
please help me..
I am using MinifyJS.tt which is a T4 template to minify all my JS files automatically.
In my aspx files, I am referencing all the javascript files.
Now, I want to add a condition (maybe compiler directive) to use the original JS file when I am debugging the application, and to use the minified JS files when I simply run the application without debug.
I tried using #if in the aspx page, but that did not seem to work.
Can we make use of preprocessor directives in aspx pages?
Is there an alternative way to achieve my goal?
You can use the following:
if (!HttpContext.Current.IsDebuggingEnabled)
Script = OptimizeScript(Script);
Further.....there are a couple of comments than discuss the topic further.
From Wilco Bauwer he comments that this property encapsulates the web.config setting and doesn't take the page level debugging into account and if you wanted to....
bool isDebuggingEnabled = Assembly.GetExecutingAssembly().IsDefined(typeof(DebuggableAttribute));
....this is the kiddy to achieve it!!
and Peter Bromberg (C# MVP) offers up another solution using the Global.asax.cs file and a static global application flag being set in the Application_Start event.
public static bool IsDebugMode = false;
protected void Application_Start(object sender, EventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached) IsDebugMode = true;
Taken from Steves blog