tags:

views:

378

answers:

2

Hi,

I have a database table where the user marks files to be downloaded. Subsequently, I browse this table and need to create a fileList to pass to an ActiveX downloader. My routine works locally and on the server for ONLY the first file. I know my logic must be bad, but I cannot find it. All of these files are always in the same server directory which is as follows: "D:\inetpub\vhosts\WebSite.com\sessionVideos\"

Sub (GetFileList)
Dim dtVideosSelected As New DataTable
Dim drVideosSelected As New DataRow
Dim strSourceDirectory As String = "sessionVideos/"
Dim strServerBasePath As String = Server.MapPath(strSourceFileDirectory)
Dim strFileName As String
Dim fileInfo As System.IO.FileInfo
Dim i As Int16

Response.Clear()
Response.ContentType = "text/plain"
Response.Charset = "UTF-8"

i = 0
Do While i < dt VideosSelected.Rows.Count
    drVideosSelected = dtVideosSelected.Rows(i)
    strFileName = drVideosSelected("VID_FileName")
    If File.Exists(strServerbasePath & strFileName)
        fileInfo = New System.IO.FileInfo(strServerbasePath & strFileName)
        Response.Write("*/* | " & fileInfo.Length & " | " & fileInfo.Name & " | ")
        Response.Write(EncodeFileName(strSourceFileDirectory & fileInfo.Name) & vbCr
            & vbLf)
    End If
    i += 1
Loop

Response.End()
Response.Flush()
End Sub

Private Function EncodeFileName(ByVal fullPath As String) As String
    Return Server.UrlEncode(fullPath).Replace("+", "%20").Replace("%2f", "/")
End Function

I have tried a lot of differnet things with no success. Thank you for any assistance!

James

A: 

To download a file,

Dim b() As Byte = System.IO.File.ReadAllBytes(strServerbasePath & strFileName)
Response.Clear()
Response.ClearHeader()
Response.AddHeader("Content-Type: application/octate-stream")
Repponse.AddHeader("Content-Length: " & b.Length)
Response.AddHeader("Content-Disposition: attachment; filename=" & strFileName)
Response.BinaryWrite(b)
Response.Flush()
Response.End()
adatapost
Thank you, but I don't need to know how to download a file. I am using a purchased ActiveX control to do the job. I am downloading multiple files and need to create the file list here to pass to the downloader. The problem is that it is only picking up the first file. I am sure there is an issue with my written logic here. Again, this works locally just fine but not on the server.Thanks,James
James
A: 

Ok, we have an answer.... I actually had double file extensions on the files that were not working but the option to hide known extensions was turned on (I guess by default). The .avi files looked the same as the others so I guess it was considering .avi to be an "unknown" file type. Whatever!

The answer is on my other post here:

http://stackoverflow.com/questions/1386338/why-is-fileinfo-showing-an-extra-file-extension

Thanks, James

James