I am having a big problem downloading a file from my custom DNN Dynamic Module. From within the following Button Click server-side event, I run the following code. The dowload code works perfectly on my development PC but fails on the production server. I run Windows XP, VS2005, CLR 2.0, DNN 441, IIS6, IE7. I am not sure if it matters but my production server runs as Https:
----- Code Begins ---------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = String.Empty
Dim sFilename As String = String.Empty
sFilename = "TRVBilling_All_" & wcDateRange.DataValue.ToString & ".csv"
File.Delete("C:\Program Files\CoreBillingTempDir\" & sFilename)
Dim sw As StreamWriter = File.CreateText("C:\Program Files\CoreBillingTempDir\" & sFilename)
Dim _dt As DataTable = CType(Session("GetTRVBilling_CurrentDataSet"), DataSet).Tables(_intTable)
For Each col As DataColumn In _dt.Columns
s = s + col.ColumnName + ","
Next
sw.WriteLine(s.TrimEnd(","c))
s = ""
For Each row As DataRow In _dt.Rows
For Each col As DataColumn In _dt.Columns
s = s + row(col.ColumnName).ToString + ","
Next
sw.WriteLine(s.TrimEnd(","c))
s = ""
Next
'sw.Flush()
sw.Close()
Dim _checkFile As FileInfo
_checkFile = New FileInfo("C:\Program Files\CoreBillingTempDir\" & sFilename)
If _checkFile.Exists Then
Dim fs As New FileStream("C:\Program Files\CoreBillingTempDir\" & sFilename, FileMode.Open, FileAccess.Read)
Dim length As Integer = Convert.ToInt32(fs.Length)
Dim byteBuffer(length) As Byte
fs.Read(byteBuffer, 0, length)
With Page.Response
.Clear()
.ContentType = "text/csv"
.AddHeader("content-disposition", "attachment; filename=" & sFilename) ' Forces the file download
.AddHeader("Content-Length", length.ToString())
.AddHeader("Accept-Ranges", "bytes")
.AddHeader("Accept-Header", length.ToString())
.OutputStream.Write(byteBuffer, 0, length)
.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest() ' This replace .End() which cause a Threading exception
End With
End If
End Sub
----- Code Ends -----------
The normal File Download dialog box opens (correctly!) on my development pc (gives the user the chance to either Open Save Cancel) and the subsequent file download works perfectly (Btw, I am downloading .Csv type files and I did exclude the mime type (text/csv) in the compression config file). On my production server, when I run the above code, I get a dialog the comes up for a few seconds and indicates that the code is trying to download Default.aspx from my production web site: www.ncstrvprocessing.com. Eventually this times out and an error comes up and says: "Internet Explorer cannot download Default.aspx from www.ncstrvprocessing.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later." Any Help is greatly appreciated!!