views:

1001

answers:

2

I am accessing the SHDocVw.InternetExplorer from the SHDocVw.ShellWindowsClass(). I can see the page that the browser instance is currently on (the LocationURL property), but what I really need is the last get request that was done for the browser. My specific need is that my application was just launched to handle a file that was downloaded to the user's system via a link on the current web page. I need to know the URL of that file. LocationURL gives me the URL of the page that the link is on, but I need the URL of the file/link.

EDIT: The web application I've been trying to interface with is SharePoint. I wasn't able to find a way to extract the URL of the last clicked link (file downloaded) from Internet Explorer, so now I'm hoping to find a way to get that information from either SharePoint itself, or piggyback on the Name ActiveX control that SharePoint uses to manage the download of MS Office documents. Any SharePoint/Name ActiveX experts out there?

+1  A: 

Since you can't get the url from Internet Explorer's history using IUrlHistoryStg::EnumUrls http://msdn.microsoft.com/en-us/library/aa767720%28VS.85%29.aspx

try making sure the file association is setup one the box and that your app can take a file path from the command line to start up.

I added these keys to my registry

[HKEY_CLASSES_ROOT\.sdr]
@="sdrfile"

[HKEY_CLASSES_ROOT\sdrfile\shell\open\command]
@="\"D:\\Shenanigans\\MyGreatApp.exe\" \"%1\""

on a Win7 box and IE/Sharepoint figured it out. If you poke around HKCR you'll see that it can get more complicated to setup file associations, but see if this works.

nick
I think that's going to give me what's in IE's "visited pages" history. When you click a link to download a file, that doesn't appear in IE's history.
Steve
Doh! Could you elaborate on how windows/IE knows to open your app? Are your links using a custom protocol or does IE use the MIME type to launch your app? If it's one of these you should be able to add some stuff to the registry and get the url as a parameter: http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx or http://msdn.microsoft.com/en-us/library/ms775147(VS.85).aspx#Registry_Locations.If you're using another method please share:)
nick
It's a plain old anchor tag (a href="http://...). IE is launching my app based on the mime type/file extension being the registered default program for that file extension type.I checked out those MSDN articles, and I'm not sure that would work for me. I don't control the application that's formatting the links on the page.
Steve
Actually, I guess it's a little more complicated than a "plain old anchor tag". It's produced by SharePoint 2007:<A onfocus="OnLink(this)" HREF="/Working/Development/asdf%202009/test4.sdr" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','','0','SharePoint.OpenDocuments','','','','62','1','0','0x7fffffffffffffff')">
Steve
Can your app can take a file path from the command line and/or can you double click on one of these files in Explorer.exe or on the desktop and have it open up in your app? I wrote a simple WinForms app that displays the contents of text file with an sdr extension and got it to launch from my sharepoint site by adding the two registry keys I added to the answer above.
nick
I actually have that registry structure in place. I get the local filename (in a temp directory) as a parameter, not the url. You are getting the URL?
Steve
Nick: To answer your questions more directly: Yes, my app takes the file path as a parameter. Sharepoint correctly opens my app and passes the local (temp) file path to my app. What I need, however, is the URL on SharePoint where I can find that file (I'm doing web services to check out, check in, etc based on edits done to the local file). I have a very ugly workaround in place to search the entire site for the filename (minus any pathing), and present the user with a list of possible matches to choose from. I was looking for a better way to get that URL.
Steve
I now understand what you're doing and why you need the url. I don't have an answer but a few obeservations/suggestions* Try tagging this question as sharepoint since there must be a sharepoint guru who has dealt with this before* I think Sharepoint/Office use activex controls to facilitate opening documents, maybe you can do something similar/piggyback on the sharepoint ones* There still might be registry/com object magic that could make this work but its beyond meGood luck and post you answer if you figure it out:)
nick
Thanks. I'll try tagging this as you suggest.
Steve
A: 

Sink DWebbrowserEvents2::OnBeforeNavigate2.

jeffamaphone
I don't think this would work for me, as my application is launched in response to the link being clicked. By the time my application comes up to run, the event has already fired.
Steve
What kind of link is this? Also, ShellWindowsClass is deprecated, so expect it to stop working completely eventually.
jeffamaphone
The web page is produced by SharePoint:<A onfocus="OnLink(this)" HREF="/Working/Development/asdf%202009/test4.sdr" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','','0','SharePoint.OpenDocuments','','','','62','1','0','0x7fffffffffffffff')">
Steve
So, you get the name of the document (.../test4.sdr). Can't you use that to map back to the link on the page?
jeffamaphone
You mean by loading up the HTML and finding the link? I was hoping to avoid that, as it would be vulnerable to changes in the page layout.
Steve
I think the answer to your question at this point is "no, there is no way to do that." Basically you need for something in the system to remember some arbitrary link has been clicked. Nothing does that. You'll have to write a BHO.
jeffamaphone