Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I'm trying to determine what a user did after clicking the Export button under a grid of error records. The export is to an Excel spreadsheet but before seeing that sheet, they are presented with a dialog box (Windows 7) with choices to Open, Save or Cancel.

The process of creating the Excel wb and sheet are all done in code I'm not familiar with (added by someone else) and now I'm faced with the task of trying to determine whether they actually opened or saved the data or just clicked cancel.

I need to know this so I can allow or disallow other processing.

The following code is handling the exporting process:
VB
Private Sub ErrorsExcel()
        Dim sHTTPStatusCode As String
    Try
        Dim dtData As WorkDS.DataImportDataTable = CType(Session("BadWorkData"), WorkDS.DataImportDataTable)

        dtData.Columns.Remove("ImportID")

        Dim colIndex As Integer = 0
        Dim rowIndex As Integer = 0

        Dim sw As StringWriter = New StringWriter()
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)

        Response.ClearContent()
        Dim grid As GridView = New GridView()
        grid.DataSource = dtData
        grid.DataBind()
        grid.RenderControl(htw)

        Dim sFile As String = "attachment; filename=Errors.xls"
        Response.ContentType = "application/vnd.ms-excel"
        Response.AppendHeader("Content-Disposition", sFile)
        Me.EnableViewState = False
        Response.Write(sw.ToString())

        Dim sTab As String = ""
        sHTTPStatusCode = Response.StatusCode.ToString()

        Response.End()

    Catch ex As Exception
        lblErrors.Text = ex.Message
    Finally
        If sHTTPStatusCode = "200" Then
            cbIgnoreErrors.Enabled = True
        End If
    End Try

    Reset()

End Sub


What I have tried:

After some research trying to find returned codes or status codes related to the process, I settled for sHTTPStatusCode = Response.StatusCode.ToString() and just checking to see if "200" was being returned and then using that value in the Finally section. I soon realized this didn't tell me what choice they selected and only signaled proper request completion.

So, I need to know if they selected Open/Save or cancelled.
Any help would be much appreciated.

Red.
Posted
Updated 28-Apr-16 8:10am
v2
Comments
Richard Deeming 28-Apr-16 14:13pm    
AFAIK, you can't. The server sends the file to the client, but there is no way for the server to know what the client does with it after that.
ZurdoDev 28-Apr-16 14:37pm    
As Richard said, you can't. Why do you want to know?
Redvan 28-Apr-16 14:39pm    
Because "the powers that be" want to force the user to acknowledge that they have saved the records in error, or at least reviewed them. If they click Cancel - they haven't.

There is more to do after this event and that is to be conditioned on the fact that they didn't click Cancel.
ZurdoDev 28-Apr-16 14:43pm    
You would have to use a windows app or create a browser plugin. Because the way http works is, as Richard said, it sends the file to the client and then disconnects. It's then your browser that puts up the Save/Open/Cancel dialog. The server has no connection at that point and no knowledge of what happens.

The "powers that be" may want to rethink what they want.
Richard Deeming 28-Apr-16 14:49pm    
If you just want to verify that they've opened the file, how about generating a random code, saving it in the session, and including it at the bottom of the file? Then, when the user confirms they've reviewed the file, they have to type in the code.

Of course, there's nothing to stop them from opening the file, scrolling to the bottom, and reading the code without reviewing the data. But that's not the sort of problem you can solve with code. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900