You must Sign In to post a response.
  • Category: .NET

    Alert is not showing after downloading ZIP file

    Hi Guys,

    I used functionality to download PDF ZIP file for different users one by one.

    I stored user those PDF file not generated successfully & want to show alert of those users list.

    Users list is assigning in variable and file is also downloading for successfully generated pdf of users but alert is not showing for not generated PDF user.

    My code are listed below, can you suggest me how to do that?

    Private Function DownloadZip(ByVal strFolderpath As String, ByVal strMissingSub As String) As Boolean
    Dim zip As New ZipFile()
    Dim DocumentsArray() As String
    Dim fInfo As FileInfo = Nothing

    Try
    If Not Directory.Exists(Server.MapPath(ConfigurationManager.AppSettings.Item("uploadfilepath").Trim()) + "\" + Me.HProjectId.Value.ToString() + "\" + strFolderpath) Then
    Return True
    End If

    DocumentsArray = System.IO.Directory.GetFiles(Server.MapPath(ConfigurationManager.AppSettings.Item("uploadfilepath").Trim()) + "\" + Me.HProjectId.Value.ToString() + "\" + strFolderpath + "\FinalReportLinear")
    If DocumentsArray.Length = 0 Then
    Return True
    End If
    Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
    zip.AlternateEncodingUsage = ZipOption.AsNecessary
    zip.AddDirectoryByName("Files")
    For i = 0 To DocumentsArray.Length - 1
    fInfo = New FileInfo(DocumentsArray(i))
    If fInfo.Exists Then
    Dim filePath As String = fInfo.FullName.ToString()
    zip.AddFile(filePath, "Files")
    End If
    Next i
    response.Clear()
    Dim zipName As String = [String].Format("Zip_{0}.zip", DateTime.Now.ToString("yyyyMMMddHHmmss"))
    response.ContentType = "application/zip"
    response.AddHeader("content-disposition", "attachment; filename=" + zipName)
    zip.Save(response.OutputStream)
    response.Flush()
    response.End()
    Return True
    Catch ex As Exception
    Me.ShowErrorMessage("...........DownloadZip", ex.Message, ex)
    Return False
    Finally
    If strMissingSub <> "" Then
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "UniqueID", "alert('Dossier File Not Generated For Subject: " + strMissingSub + "')", True)

    End If
    End Try
    End Function

    Thanks in advance.
  • #768991
    Hai Aditya,
    Looks like the code is correct and as per the code, it should show the alert message. I made a little change in your code so your can check it should work:

    Private Function DownloadZip(ByVal strFolderpath As String, ByVal strMissingSub As String) As Boolean
    Dim zip As New ZipFile()
    Dim DocumentsArray() As String
    Dim fInfo As FileInfo = Nothing
    Try
    If Not Directory.Exists(Server.MapPath(ConfigurationManager.AppSettings.Item("uploadfilepath").Trim())
    + "\" + Me.HProjectId.Value.ToString() + "\" + strFolderpath) Then
    Return True
    End If
    DocumentsArray = System.IO.Directory.GetFiles(Server.MapPath(ConfigurationManager.AppSettings.
    Item("uploadfilepath").Trim()) + "\" + Me.HProjectId.Value.ToString() + "\" + strFolderpath +
    "\FinalReportLinear")
    If DocumentsArray.Length = 0 Then
    Return True
    End If
    Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
    zip.AlternateEncodingUsage = ZipOption.AsNecessary
    zip.AddDirectoryByName("Files")
    For i = 0 To DocumentsArray.Length - 1
    fInfo = New FileInfo(DocumentsArray(i))
    If fInfo.Exists Then
    Dim filePath As String = fInfo.FullName.ToString()
    zip.AddFile(filePath, "Files")
    End If
    Next i
    response.Clear()
    Dim zipName As String = [String].Format("Zip_{0}.zip", DateTime.Now.ToString("yyyyMMMddHHmmss"))
    response.ContentType = "application/zip"
    response.AddHeader("content-disposition", "attachment; filename=" + zipName)
    zip.Save(response.OutputStream)
    response.Flush()
    response.End()
    Return True
    Catch ex As Exception
    Me.ShowErrorMessage("...........DownloadZip", ex.Message, ex)
    Return False
    Finally
    If strMissingSub <> "" Then
    ScriptManager.RegisterStartupScript(Me, typeof(Page), "UniqueID", "alert('Dossier File Not
    Generated For Subject: " + strMissingSub + "')", True)
    End If
    End Try
    End Function

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768994
    Hi Pawan,

    I checked provided code but its not working.

    Thanks,
    Aaditya


  • Sign In to post your comments