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:

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:
Private Sub ErrorsExcel()
        Dim sHTTPStatusCode As String
        Dim dtData As WorkDS.DataImportDataTable = CType(Session("BadWorkData"), WorkDS.DataImportDataTable)


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

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

        Dim grid As GridView = New GridView()
        grid.DataSource = dtData

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

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


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


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.

Updated 28-Apr-16 8:10am
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