C# code to simulate clicking on links - c#

Please take a look at this website. It allows you to change the date using either the calendar or the 'next' and 'previous' links. Whenever a date is changed, the match data below is updated. I want to programmatically select a date, then retrieve the URL behind the 'Boxscore' link in the lower part.
I have tried the WebBrowser control, which often doesn't load the page fully, and if it does, I can't find a way to interact with the controls. (I'm stuck at webBrowser.Document.GetElementById("calendar id")). I've also tried WatiN(watin.org), which causes problems with dependencies:
Unhandled Exception:
System.IO.FileNotFoundException: Could
not load file or assembly
'Interop.SHDocVw, Version=1.1.0.0,
Culture=neutral,
PublicKeyToken=db7cfd3 acb5ad44e' or
one of its dependencies. The system
cannot find the file specified
I'm also trying to work something out using IeUnit, but currently I have no idea how to use it in a C# program.
Does anyone have any libraries to recommend/any other method of getting the data?

Try just sendkeys and use the tab button to move through links, enter to goto hyperlinks, and f5 to refresh.

Try Selenium. IMHO its much better than Watin.
Download with the C# (Selenium WebDriver) link.
Edit: First tutorial that popped up on google. Looks ok.

I answered a similar question recommending HtmlUnit under .NET: Looking for a simple C# scraping library with JavaScript support

I have also used watin API for screen scraping, from the exception you have posted, does not reflect any problem in your code. You must be have missed a reference to the "Interop.SHDocVw.dll" file or else if you had added a reference, please do it again.
If this does not help you out then please check that .NET framework is properly installed in your machine and .dll file are there in the assembly to load from. I was getting the same problem and I solved it in this way.

Related

Writing a Custom IIS Directory Listing Module

I'm currently looking to replace the in-built "DirectoryListingModule" in IIS 7.5 with a custom version to make the listing a little prettier. The problem is I cannot seem to find anything on the subject of writing a managed module to do this myself. I've read the IIS 7 module/handler tutorials over on Microsoft's site, which are helpful albeit very basic. I've also seen Mike Volodarsky's implementation but unfortunately no source code is provided. The only other resources I can find link back to either Volodarsky's blog or the Microsoft page (which is also written by Volodarsky!). I guess what I'm saying is I don't know how to get from the basic module in the Microsoft tutorial to the directory listing functionality of Volodarsky's example.
If anyone can provide a hint on how to tackle this I'd be very grateful. Also please let me know if any of this isn't clear (I'm terrible at writing).
Thanks in advance :)
Edit - Just to be clear, I realise I have a lot of reading to do and am not looking for anyone to do my work for me.
Mike Volodarsky's implementation is really simple:
you create a module that intercepts requests to "directory" urls within your application.
This module will create a collection of object that rappresents directory structure and save it in the httpcontext
Then you load an aspx page which binds to the httpcontext saved content.
I don't get what you are asking for?
If you are not able to develop that module you can use the Mike Volodarsky's one and just customize the aspx page...
The PreRequestHandlerExecute event in an ASP.NET Application is where you can process and replace the default IIS handlers.
You have two option:
Use the Application_PreRequestHandlerExecute event in the Global.asax file.
Write a custom IHttpModule and use the OnPreRequestHandlerExecute event.
Regardless of which method you prefer to use, you must ensure that the request is a directory not a file, other registered handler, and so on.
Use the below code to check for it:
if (!Directory.Exists(context.Request.PhysicalPath))
return;

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack error message

whenever i Response.Redirect("myexamplepage.aspx"); it either keep looping and then lastly show the page is unable to view or show this above error. However, if i Response.Redirect("http://www.google.com.sg"); it works.
I tried all the methods i found online such as the following:
Response.Redirect(url,false)
Redirecting url outside the try-catch
I'd also make sure that my project is running debug mode.
BUT i am still facing this problem. It is like so random because previously i dont have any problems redirecting to my url. Please provide me with solutions thanks.
This error occures most of the time when you are trying to redirect to a new page, while the current page is still trying to complete it's proces.
You can find more information about the issue right here:
http://support.microsoft.com/kb/312629/EN-US/
So change your code to the following:
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect ("myexamplepage.aspx", false);
As Rob Angelier said, the problem is related to an uncompleted process.
That means, make sure you move the Response.Redirect out of the using statement!
This may not be an actual answer to the specific question but I thought it would help others struggling with the same type of problem :)

How to create a help file

I want to create a help file opens when pressed F1 anytime. How to create it and include to code?
You are asking two things which are separate issues:
Create a help file.
This can be tricky depending on how you do it. There are many different options, some launch a web browser to a online help while others launch a help viewer of some kind. I have also seen people having simple help viewer implemented in simple controls like some kind of browser control or rich text viewer. To create a external file (like a *.chm file) I would use a commercial package like robohelp, there are SDKs from Microsoft, but packages like RoboHelp makes lift so much easier.
Launch the help
To get the help to be displayed you normally (in the case of an *.chm file or an web browser) need to launch the viewer program. The help SDK from Microsoft contains help for this, but you may also just lauch the program as any other program. Take a look at the System.Diagnostics.Process class.
If you want to create a CHM help file you may check out HelpNDoc which is a perfect tool to create PDF,HTML and CHMs instantly. If it comes to launching, mrz is also perfectly right.
There is a help SDK that microsoft provides
check it out:
http://msdn.microsoft.com/en-us/library/ms670169
Im assuming this is what your looking for?
you could set F1 to one of these HTML pages?
If your program is rather simple, a single HTML file opened in the user's default browser should be ok. But if Your application is a bit more complex, there's no real alternative to a chm file.
You might also include a PDF which describes common use-cases. (Like a book about using your software)
You can create your help in HTML format and for viewing, you can create a Form which has an embedded browser in it, and load the index (or whatever you call the first page) in the browser.

Display HTML in a silverlight application

I need to display HTML in my silverlight application and cannot find a way of doing it. I cannot use the web browser control as it needs to be able to run in or out of a browser.
Does anyone know of a good way to do this, because all I can think of doing at the moment is running replace methods on the text to just replace the tags with C# equivalents eg(<br /> to \n).
The way I do it is to check if the application is running inside the browser and change the means of display accordingly. If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/book/downloadfile/4638.
Hope this helps...
Chris
I believe what you are looking for is HTML Bridge.
Edit I'm am actually now unsure if you'll still have access to javascript if you're running this OOB. I'm going to look into this some more and will further update. I'll still leave the answer up though for reference.
Second Edit Here is what I've found. HTML Bridge is disabled when you run silverlight out of browser. This disables access to the HTML DOM as well as Javascript. However, according to a comment on this site:
HTML Bridge is not available when you first install a OOB app. But you CAN force it if you modify the index.html in the folder where the app is installed just adding the enablehtmlaccess parameter.
It works!
You can even create dynamic HTML elements using the well-known methods of the HtmlPage class. You can even open a new browser window with the Navigate() method and its "_blank" parameter.
Keep in mind this information was posted about SL 3. Its possible that this may have changed, but I doubt it. So it seems that what you may want to do is build a script into the startup of your SL app that detects whether or not your app is running out of browser. If it is then you may want to have some script to call that can modify this file for you.
There recently was a similar question.
I posted a link there to an implementation that parses and displays HTML inline in Silverlight. Of course, it will work only with simple HTML, but maybe you can expand it to your needs.

Home/Landing screen design for a website in asp.net

I have an web based application. The content for the Home page has been currently mentioned in the HTML code for the Home page using , and tags. To change the content anytime in future, it needs to be changed in the HTML code. :(
Is there a way that we can pick up the content from some external place and get it reflected through the website. This ways, any change if required can be made at the external location without referring to the application's code.
Please advise if there is any solution for it.
Thanks.
You can
Use a database
Include external files using Server Side Includes
Read external files and write their contents and an alternative method
Sounds like you're looking for a Content Management System (CMS), which will allow your content editors access to modify only specific blocks of a page that you specify.
There are a ton out there to do what you want, so you don't have to start from scratch. Just Google 'CMS'.
Although I haven't used it myself, DotNetNuke is a popular one these days and has a free version.

Categories

Resources