Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I used zip store class in my web application which is in vb.net 2005 VS 2.0.By using this I have created a function that creates zip file after that I am calling a function to provide download option for created zip file .

Its working fine for local host. But when I am trying to call same through IP from my system or other system .its not working for zip file. But for other file like pdf which is in same directory with same permission ,this function is working fine.

can you suggest me where is the problem.

following is code of download function.....


'''calling function
DownloadFile(strFileName, strName)


VB
Public Sub DownloadFile(ByVal fname As String, ByVal strname As String, Optional ByVal forcedownload As Boolean = True)
           Try
               'Dim path As Path
               Dim fullpath = IO.Path.GetFullPath(fname)
               Dim name = IO.Path.GetFileName(fullpath)
               Dim ext = IO.Path.GetExtension(fullpath)
               Dim type As String = ""
               If Not IsDBNull(ext) Then
                   ext = LCase(ext)
               End If
               Select Case ext
                   Case ".htm", ".html"
                       type = "text/HTML"
                   Case ".txt"
                       type = "text/plain"
                   Case ".doc", ".rtf"
                       type = "Application/msword"
                   Case ".csv", ".xls"
                       type = "Application/x-msexcel"
                   Case ".pdf"
                       type = "Application/pdf"
                   Case ".zip"
                       type = "application/x-zip-compressed"
                   Case Else
                       type = "text/plain"
               End Select
               If type <> "" Then
                   Response.ContentType = type
               End If
               Dim fs As FileStream
               fs = File.Open(fullpath, FileMode.Open)
               Dim bytBytes(fs.Length) As Byte
               fs.Read(bytBytes, 0, fs.Length)
               fs.Close()
               Response.Buffer = True
               Response.ClearContent()
               Response.ClearHeaders()
               Response.ContentType = "Application/pdf"
               Response.AddHeader("Content-Disposition", "attachment; filename=" & strname + ".pdf")
               Response.AddHeader("Content-Length", bytBytes.Length)
               Response.BinaryWrite(bytBytes)
               'Response.End()
           Catch ex As Exception
               ' do nothing
           End Try
       End Sub
Posted
Updated 22-May-11 23:36pm
v3

1 solution

In your code you spend a lot of time setting up the different possible alternate file types to download, yet when it comes to actually setting the file type you hard code it to pdf ie:-

C#
Response.ContentType = "Application/pdf";


instead of

C#
Response.ContentType = type;


Hope this helps
 
Share this answer
 
Comments
NuttingCDEF 23-May-11 5:45am    
Good call - my 5
Wayne Gaylard 23-May-11 5:55am    
Thanks
tej n. upadhyay 23-May-11 11:01am    
Hi,
Thanks for your valuable response.
this is a common function in a class for download any type of file.it work successfully also for zip file if I run application through localhost.But does not support when I am trying to run through ip (issue showing only for zip file not for other).


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