Skip to main content

Microsoft Silverlight

Unanswered Question Browser Open/Save dialog not showingRSS Feed

(0)

Rob T
Rob T

Member

Member

0 points

2 Posts

Browser Open/Save dialog not showing

I'm working on an application in Silverlight 3.0. One of my features works as follows:
1) The SL client has a button, which when clicked, makes a REST call to the web server
2) The REST service generates an Excel file (on the server) and returns a URL + ID to the SL client in the browser
3) The SL client uses the System.Windows.Browser.HtmlPage.Window.Navigate method to load the URL with the ID in the querystring
4) The URL goes back to the same web server, where an ASPX page handles the request and streams the file to the client

At this point the browser should show a Open/Save dialog to open or save the Excel response. The web server ensures the appropriate header:

Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader(
"Content-Disposition","attachment;filename=" + fileName);
Response.WriteFile(filePath);
Response.Flush();

If I simply open a new browser and type in the address manually, it works perfectly.

The problem is when I try to do the same thing from the SL client. When it uses the HtmlPage.Window.Navigate method, it looks like the page just locks up. The Open/Save dialog doesn't show. After some frustrated poking around, I realized that the SL client is not really locked up. The browser is waiting for the user to click on the Open/Save dialog! Except the dialog isn't visible. If I tap the browser's menu, or click the Alt button, the dialog immediately displays itself. I got this to happen consistently on both IE 6 and IE 7 on several machines (the company is stuck on those 2 versions).

Anyone have any idea why the dialog seems to be isntantiated but isn't showing up until i click something on the browser itself (other than the SL content)? Is this some weird threading behavior between SL and the browser? And more importantly, how do I get it work?

ken tucker
ken tucker

All-Star

All-Star

16346 points

2,499 Posts

Re: Browser Open/Save dialog not showing

From the msdn documents

The ShowDialog method can only be called from user-initiated code, such as a button Click event. If ShowDialog is called from code that is not user-initiated, such as a Page Loaded event, a SecurityException is thrown.

The Silverlight plug-in does not support OpenFileDialog in full-screen mode. In most cases, displaying this dialog box in full-screen mode will cause the plug-in to revert to embedded mode. To avoid issues on some browsers, you should exit full-screen mode before using this class. For more information, see Full-Screen Support.

Are you calling the showdialog method in the button click or event or from a webservice call completed event? 

Rob T
Rob T

Member

Member

0 points

2 Posts

Re: Browser Open/Save dialog not showing

I'm not calling ShowDialog at all. I'm calling the DOM's Navigate() method to load the excel file from the web server. When the browser detects the response header (which tells it the file is an app-specific document), the browser itself shows the Open/Save dialog. The dialog does in fact open up, but for whatever reason, it's hidden until I move focus away from the SL object to somewhere else on the browser (like the browser's menu).

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities