I can't get my C# program to open the html page at the desired location.
E.g.
System.Diagnostics.Process.Start(@"C:\file.htm");
works fine. It opens the page at the top.
But if I type
System.Diagnostics.Process.Start(@"C:\file.htm#bookmark");
it still just opens at the top of the page (instead of at the bookmark where I want it to open.
Any ideas?
E.g.
System.Diagnostics.Process.Start(@"C:\file.htm");
works fine. It opens the page at the top.
But if I type
System.Diagnostics.Process.Start(@"C:\file.htm#bookmark");
it still just opens at the top of the page (instead of at the bookmark where I want it to open.
Any ideas?
Sam HobbsPosted Aug 10, 2011, 11:39 AM
Go to the Solution Explorer and in your project right-click on the "References" node. Then select "Add Reference..." (at the top of the context menu). A window will open with tabs along the top for .Net, COM, Projects, Browse and Recent. The shdocvw.dll is quite elusive, so for that file, use the Browse tab. Just browse to C:\Wiindows\System32\shdocvw.dll (the path might be a little different for your system).
Note that in the code I posted, "SHDocVw" is the namespace name. You can add a "using SHDocVw;" so you do not need to put "SHDocVw." in your source code but I prefer not to do that. Similarly, you could use a "using System.Diagnostics;" to avoid putting "System.Diagnostics." in the program.
So in the future, when you see something saying to add a reference for something, you have a clue to what that means. There are many details, but at least now you have a clue. Usually for .Net programs when it says to add a reference, you must add a reference.
Zoran HorvatPosted Aug 10, 2011, 10:35 AM
R ONPosted Aug 10, 2011, 10:32 AM
Sam HobbsPosted Aug 10, 2011, 10:22 AM
Zoran, I am sorry that I misunderstood you.
R ONPosted Aug 10, 2011, 4:41 AM
R ONPosted Aug 10, 2011, 4:40 AM
Zoran HorvatPosted Aug 10, 2011, 3:46 AM
System.Diagnostics.Process.Start(@"http://www.b92.net/info/komentari.php?nav_id=530780#k5592722");
This is a long page and it gets opened somewhere in the middle when this executes, exactly where the corresponding anchor in HTML is located.
However, other browsers might not act the same. As you said, it is possible to start particular browser from code and then to enforce it opening particular URL which includes bookmark.
Zoran
Sam HobbsPosted Aug 9, 2011, 10:06 PM
That is an intersting challenge. I am not sure how to solve that problem. Oh, wait; I have an idea.
You could do something such as the following, which uses the InternetExplorer Object. To do this, you need to add a reference to SHDocVw.dll which is in your Windows\System32 directory.
ie.Visible = true;
ie.Navigate(@"C:\file.htm#bookmark");
Zoran HorvatPosted Aug 9, 2011, 1:02 PM
Try this url:
System.Diagnostics.Process.Start(@"http://www.b92.net/info/komentari.php?nav_id=530780#k5592722");
That will open in the middle of the page as it should - at least it did to me.
If it doesn't, then please state which Web browser are you using. I'm using Firefox and this statement above works fine.
Zoran