Cannot show html-file in a new TAB

Discussion in 'Site Programming, Development and Design' started by John DeGe, Oct 2, 2015.

  1. Hello, all...
    I have a button on my page (using AJAX) that shows an html-file in a new browser TAB.
    This works great on my local VS2012 ASP.NET project.
    However, when I upload the report pages to Winhost server, the button does NOT show the html-file at all.

    My Code is as follows:
    Dim sFileShortName As String = "HistoryDateFleetReport.html"
    Dim sFQFName As String = "~\HTML_Reports\" & sFileShortName
    Dim sServerFileName As String = HttpContext.Current.Server.MapPath(sFQFName)
    sRet = sServerFileName
    lblFileName.Text = sFQFName
    lblMapPath.Text = sRet


    The last two sentences place the Filename and MapPath into the page so I can see them during execution as follows:
    sFQFName = "~\HTML_Reports\HistoryDateFleetReport.html " << as expected
    MapPath = "E:\web\nnnnnn\HTML_Reports\HistoryDateFleetReport.html " << Is this correct?

    I know that the generated html-file is created on the Winhost server and using FileZilla -- I can view the html-file in a browser.

    Here is the code that LAUNCHES the html-file:
    Dim strFileName As String = hidReportHtmlName.Value

    ' Display into a new browser-tab.
    System.Diagnostics.Process.Start(strFileName)

    Response.ContentType = "application/html"
    Response.AddHeader("content-disposition", "attachment;filename=" & strFileName)
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    ScriptManager.RegisterClientScriptBlock(cmdLaunchReport, Me.GetType(), "HelpOnLoad", "window.open('" & strFileName & "','_blank','location=0,menubar=0,status=0,titlebar=0,toolbar=0');", True)
    Try
    Response.End()
    Catch ex As Exception
    Thread.Sleep(1000)
    End Try


    Any suggestions as to what is going wrong here in the Winhost server? Bad file-path? Bad MapPath?
    Thanks.
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    "MapPath = "E:\web\nnnnnn\HTML_Reports\HistoryDateFleetReport.html " << Is this correct?"

    Yes, that is correct.

    What's the value of strFileName?
     
    Michael likes this.
  3. Thank you for your reply...
    The value of 'strFileName' is that of the MapPath which is "E:\web\nnnnnn\HTML_Reports\HistoryDateFleetReport.html ".

    The problem is that the generated html-file does not appear in a new IE10 browser tab when run from the Winhost server, but DOES appear as expected when run locally from within the VS2012 project (debug-mode).
    That is why I was seeking assistance on the Winhost MapPath value.

    Is there a permissions/security option not being set on the Winhost server that should be set?
    What could cause this code to fail?
    I will now try to capture the CATCH ex message-text and place it into the page.

    Any advice will be greatly appreciated.
    Thanks.
     
    Last edited by a moderator: Oct 14, 2015
  4. Elshadriel

    Elshadriel Winhost Staff

    Then that's probably the problem. It opens locally because it knows how to reach a C: or E: drive through the file system. You're also using the Javascript window.open command which expects a URL. So when say window.open(strFileName), the browser is probably looking on your local computer's E: drive for the file, not the Winhost server. You need to format the string to encompass the entire URL (i.e. http://www.nnnnnn.com/HTML_Reports/HistoryDateFleetReport.html). Javascript is executed client side, not server side.
     
    Michael likes this.
  5. I again thank you for your reply.
    I have narrowed down the problem to this sentence from the above code.
    System.Diagnostics.Process.Start(strFileName)
    I find on my VS2012 project that this sentence actually opens the report into a new IE10 browser tab on my local computer, but NOT in Winhost.
    Where the 'strFileName' has a value of "E:\web\nnnnnn\HTML_Reports\HistoryDateFleetReport.html", which is the Server.MapPath.

    The other code (from above, starting with Response.ContentType = "application/html") has been commented out so that the window.open does not execute.

    Are we allowed to start a process within Winhost application code?
    What else is needed to open an html-file in a new browser tab on Winhost?

    Your comments are welcome.
    Thanks...John
     
    Last edited by a moderator: Oct 14, 2015

Share This Page