locked
Create and download file: Eval + msSaveOrOpenBlob failed with error "Eval failed." RRS feed

  • Question

  • Hi,

    we try to create and download a file with the following code within Lightswitch:

    Imports System.Runtime.InteropServices.Automation
    Imports System.Windows.Browser
    Imports Microsoft.LightSwitch.Threading
    
            Private Sub Screen_Created()
                'Execute javascript
                Dispatchers.Main.BeginInvoke(Function()
                                                 HtmlPage.Window.Eval("javascript:window.navigator.msSaveOrOpenBlob(window.Blob(Array('Anita')),'Test.txt')")
                                             End Function)
            End Sub

    Running the javascript code ...

    javascript:window.navigator.msSaveOrOpenBlob(window.Blob(Array('Anita')),'Test.txt')

    ... on the following page ...

    javascripture.com/Blob

    ... works (Enter the code in the first textbox and press 'Run'). Also within debugging mode the code run without any error. But within published mode we got different errors:

    "Eval failed."

       and/or

    "[Common_MethodFailed]"
    "Arguments:"
    "Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See go.microsoft.com/fwlink/?linkid=106663&Version=8.1.31211.0&File=System.Windows.Browser.dll&Key=Common_MethodFailed"

    Could someone help us to solve the problem? Generally javascript eval works because other code in the same project like ...

    Dispatchers.Main.BeginInvoke(Function()
                                     HtmlPage.Window.Eval("window.clipboardData.setData('Text','" & Result & "')")
                                 End Function)

    ... works perfect.

    Best Regards

    Flo

    Tuesday, March 17, 2015 8:18 PM

All replies

  • EDIT:

    We already replace invalid characters within the code for clipboarddata before executing via eval: 

    Result = Replace(Result, vbCrLf, "\r\n")
    Result = Replace(Result, vbTab, "\r\t")
    Result = Replace(Result, "'", "\'")
    Is something like this also necessary for msSaveOrOpenBlob? We tested different things but nothing solved the problem ...


    • Edited by FlMa Tuesday, March 17, 2015 8:26 PM
    Tuesday, March 17, 2015 8:23 PM
  • HI Flo,

    We can save files (of arbitrary size) using the Blob constructor along with the  window.navigator.msSaveBlob and  window.navigator.msSaveOrOpenBlob methods. such as:

    window.navigator.msSaveOrOpenBlob(blobObject, 'msSaveBlobOrOpenBlob_testFile.txt'); // 

    Look into more resource: Saving files locally using Blob and msSaveBlob

    Hope it helps.

    Best regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 20, 2015 11:48 AM
  • Hi Angie,

    thanks for your reply! :)

    your given code example (that I already know) is JavaScript and it's the same like my code. To use this within Lightswitch (Client: Browser, Server: IIS) we have to use the Eval function. For this we put in into a one single line code to make it more readable. But also the following full code doesn't work:

    var csvContent='TestConent';var blob = new window.Blob([csvContent],{type: 'text/csv;charset=utf-8;'});window.navigator.msSaveOrOpenBlob(blob, 'Test.txt')
    Using this within in the Eval function ...

    Dispatchers.Main.BeginInvoke(Function()
    HtmlPage.Window.Eval("var csvContent='TestConent';var blob = new window.Blob([csvContent],{type: 'text/csv;charset=utf-8;'});window.navigator.msSaveOrOpenBlob(blob, 'Test.txt')")
    End Function)

    ... Ends with the same error.

    What is the Problem?

    Maybe there is another way to create and download a file within Lightswitch ....

    Can you help?

    BR

    Flo



    • Edited by FlMa Tuesday, March 24, 2015 10:27 AM
    Tuesday, March 24, 2015 10:26 AM