Download Handler Not Launching

Apr 27, 2012 at 5:45 PM
Edited Apr 27, 2012 at 5:46 PM

The download handler is not firing after calling DownloadFileDialog.OpenFileAsAttachment(filename).  It WAS working previously until I changed the method to OpenFileAsAttachment(uri, filename).  I have tried: cleaning/rebuilding my solution, removing/adding the references, deleting my .xap from my temp internet files and deleting the obj folders in my solution.

Code Snippets:


//Calling the method
	<add verb="GET,POST" path="FileDownload.ashx" type="HSS.Interlink.Web.FileDownload, HSS.Interlink.Web" />

	<add key="DownloadHandler" value="SLATE.Web.DownloadHandler, SLATE.Web"/>


Issue #2

The reason I changed the method signature in the first place was the handler was not working when I deployed the app to a development server.  My app was placed in a subsite on the server and I was still getting "404 - The resource could not be found" after changing my web.config to "subsite/FileDownload.ashx."  The URL in the address bar showed "http://site/FileDownload.ashx..." instead of "http://site/subsite/FileDownload.ashx..." when the 404 error was thrown.

Looking at some of your previous posts, I attempted to manually enter the uri but then the handler stopped firing.

What am I supposed to put in the URI parameter in OpenFileAsAttachment(uri, filename) anyway?  "http://site/subsite/FileDownload.ashx"? "subsite/FileDownload.ashx"?


Thank you for your help


Apr 27, 2012 at 6:55 PM

If you're running in a sub site, then you should use this on the client side

OpenAsAttachment("filedownload.ashx", "fileName");

The reason is, on the client the default is "/filedownload.ashx", which equates to Root + Handler, so when it tries to auto-resolve from the current URL (, the URI parser in .NET, see's the "/" and assumes you're merging from the Root and not from you App. So you simple need to remove the Root which is the first "/".

I know this is confusing, but is just how the .NET Uri Parser works and we had to decide which would be the default with or without the root.


Thanks for using Interlink, and let us know if we can help.

Apr 27, 2012 at 8:24 PM

Thank you hyspdrt for the quick reply.  That solved issue #2.

I was also able to get the handler to launch but I'm not exactly sure what solved it.  

My app is designed using MVVM and initially I was able to fire off OpenAsAttachment through a RelayCommand/Command in my ViewModel (since your tool needs to be user-initiated).  Once OpenAsAttachment stopped firing, I tried adding a childwindow to my app and placing DownloadFileDialog.OpenFileAsAttachment(filename) in a button click event.  It worked!  Next, I commented out the call to the child window and placed DownloadFileDialog.OpenFileAsAttachment(filename) back in my RelayCommand.  It worked again!

So I don't know why (if you're using MVVM) I had to place the call in a button event before getting RelayCommand to work but maybe this might help someone else.

For clarity, here were my steps:

  1. Button click in View is bound to a RelayCommand in my VM
  2. Commented out original code in RelayCommand method and replaced with a call to a child window
  3. In child window, added DownloadFileDialog.OpenFileAsAttachment(filename) to button click event - Starts working
  4. Commented out child window code in RelayCommand method and uncommented original code calling DownloadFileDialog.OpenFileAsAttachment(filename) - It worked again
  5. <shrug>
Apr 27, 2012 at 8:55 PM

When debugging, the click event is monitored/timed by the SL Runtime, and if too much time has passed from when the button is clicked then the user code will not work (it's like 500 ms). This is how SL validates calls from event handlers are in fact user initiated and may explain why it appeared to not work and then did work. So as long as it's executed from the originating click event (which is an SL requirment), and you're NOT setting a break point, it should work just fine with MVVM/RelayCommand.

Either way glad to hear you got it working, and let us know if you need any further assistance.