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?

Zoran HorvatRank #792 · 2.9K reputationPosted Aug 9, 2011, 9:02 AM EDT
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
Sam HobbsRank #107 · 20.5K reputationPosted Aug 9, 2011, 6:06 PM EDT
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 HorvatRank #792 · 2.9K reputationPosted Aug 9, 2011, 11:46 PM EDT
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
R ON8 reputationPosted Aug 10, 2011, 12:40 AM EDT
R ON8 reputationPosted Aug 10, 2011, 12:41 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 10, 2011, 6:22 AM EDT
Zoran, I am sorry that I misunderstood you.
R ON8 reputationPosted Aug 10, 2011, 6:32 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Aug 10, 2011, 6:35 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 10, 2011, 7:39 AM EDT
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.