Ask a questionAsk a question
 

Answer"Download Dialog" from an XBAP

Answers

  • Thursday, February 15, 2007 8:43 AMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thanks.  Finally got it.

    <TextBlock><Hyperlink NavigateUri="http://designer.cooltext.com/Setup.zip" RequestNavigate="saveToWebService">Lame Xbap Save</Hyperlink></TextBlock>

    In saveToWebService I get to call a web service and upload the file to my site, which will then get immediatly downloaded.  It's an obsene waste of bandwidth but lays the groundwork for a web workspace like they have in google docs.

     

All Replies

  • Tuesday, February 13, 2007 5:06 PMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I really need an answer for this.  Does anyone have a clue or can at least point me in the right direction?
  • Wednesday, February 14, 2007 1:49 AMAshish Shetty - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I don't believe SaveFileDialog was implemented to work in Partial Trust in .NET 3.0.
  • Wednesday, February 14, 2007 3:28 AMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     Ashish Shetty - MSFT wrote:
    I don't believe SaveFileDialog was implemented to work in Partial Trust in .NET 3.0.

    That's completley correct.  SaveFileDialog is disabled.  But, the sandbox docs I linked to still state that the IE Download Dialog is enabled under the "web integration" section, so I should be able to force the browser to download a file somehow.

  • Wednesday, February 14, 2007 7:00 PMChango V. - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    See this article: http://support.microsoft.com/kb/260519. From within an XBAP, navigate to a URL that the server will return with "Content-disposition: attachment".* That URL has to come from the site-of-origin of the XBAP, as a security restriction. Then the browser will prompt the user to Open or Save the file, and the XBAP will continue to run if they save.

    * In IIS, the setting is very easy: Open the virtual folder containing your file, get its properties, and add the header in the HTTP Headers section.

  • Wednesday, February 14, 2007 9:45 PMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm running the following:

    HiddenFrame.Navigate(new Uri("http://designer.cooltext.com/Setup.zip"));

    I've setup the header and verified that it's being sent via Fiddler.

    And am still getting the following exception.  How exactly am I suppose to navigate to this url?

    Startup URI: http://designer.cooltext.com/LogoDesignerXbap.Xbap
    Application Identity:

    System.InvalidOperationException: Failed to convert resource into object.
       at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
       at System.Windows.Navigation.NavigationService.HandleWebResponse(IAsyncResult ar)
       at System.Windows.Navigation.NavigationService.<>c__DisplayClassc.<HandleWebResponseOnRightDispatcher>b__8(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.StartDispatcherInBrowser(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

  • Wednesday, February 14, 2007 10:12 PMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I've also tried:

    ((NavigationWindow)MainApplication.Current.MainWindow).Navigate(new Uri("http://designer.cooltext.com/Setup.zip"));

     

    And got:

    Startup URI: http://designer.cooltext.com/LogoDesignerXbap.Xbap
    Application Identity:

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at MS.Internal.PresentationFramework.SecurityHelper.DemandUnmanagedCode()
       at System.Windows.Navigation.NavigationService.DelegateToBrowser(Boolean isPack, Uri destinationUri)
       at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
       at System.Windows.Navigation.NavigationService.HandleWebResponse(IAsyncResult ar)
       at System.Windows.Navigation.NavigationService.<>c__DisplayClassc.<HandleWebResponseOnRightDispatcher>b__8(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.StartDispatcherInBrowser(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.SecurityPermission
    The first permission that failed was:
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="UnmanagedCode"/>

  • Thursday, February 15, 2007 3:48 AMChango V. - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    More security to embrace: 

    1. Only a top-level navigation (within the root NavigationWindow) can be delegated to the browser.
    2. Only a user-initiated navigation can be delegated. (Considering your scenario, partial-trust code shouldn't be able to open the browser's print/save dialogs. Also, in general, we don't allow an XBAP to close itself, which navigating away does.) So, use a Hyperlink and let users click it. Of course, you can style it any way you want; it doesn't have to look like a hyperlink at all.

    Good luck.

  • Thursday, February 15, 2007 8:43 AMBryanLivingston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thanks.  Finally got it.

    <TextBlock><Hyperlink NavigateUri="http://designer.cooltext.com/Setup.zip" RequestNavigate="saveToWebService">Lame Xbap Save</Hyperlink></TextBlock>

    In saveToWebService I get to call a web service and upload the file to my site, which will then get immediatly downloaded.  It's an obsene waste of bandwidth but lays the groundwork for a web workspace like they have in google docs.

     

  • Friday, May 18, 2007 8:43 PMrfuller Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm having a similar problem, only instead of downloading a file from the server I'm trying to upload a file from the client machine to the server from inside an xbap.  I'm getting the "Failed to convert resource into object."  exception you mentioned earlier.  Unfortunetly I'm not clear how you resolved the problem.    Thanks for any help you can provide.

     

    -rfuller