Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works on local machine, but doesn't work on web

Status
Not open for further replies.

dpdg

Programmer
May 23, 2005
148
US
This is one of those "it-works-on-my-machine, but-it-doesn't-work-when-I-upload-it" kind of things. I think everyone has gone through this several times in their career.

In tests it works and downloads data in the form of a csv file that writes straight to the OutputStream. I've uploaded all the code and when I test it... you guessed it -- nothing happens!

It doesn't even return an error. Anybody know what's happening??


Private Function CreateSpreadsheet(ByVal inv As String, ByVal sta As String, ByVal rpt As String, ByVal ReportName As String) As String
Dim i, c, r As Int32, ds As DataSet, colLabel(1) As String, msg As String = ""
Dim s As New StringBuilder, temp As String

ds = GetDataSet(inv, sta, rpt)
GetHeader(colLabel, ds)
Dim rowcount As Int32 = ds.Tables(0).Rows.Count()
Dim colcount As Short = ds.Tables(0).Columns.Count

For i = 0 To colcount - 1
c = i + 1
s.Append(colLabel(i) & ",")
Next

s.Append(vbCr)

For r = 0 To rowcount - 1
For c = 1 To colcount
If Not IsDBNull(ds.Tables(0).Rows(r)(c - 1)) Then
temp = Replace(Trim(ds.Tables(0).Rows(r)(c - 1)), ",", "")
temp = Replace(temp, vbCr, " ")
temp = Replace(temp, vbLf, " ") & ","
Else
temp = ","
End If
s.Append(temp)
Next
s.Append(vbCr)
Next

Dim sSheetName As String
Dim sDate As String = Month(Now.ToShortDateString) & Day(Now.ToShortDateString) & Year(Now.ToShortDateString)
sSheetName = ReportName & "_" & sDate & ".csv"

msg = CreateXLSFile(sSheetName, s.ToString)

Return msg

End Function

Private Function CreateXLSFile(ByVal fileName As String, ByVal TextToAdd As String) As String
Dim context As System.Web.HttpContext, msg As String
context = System.Web.HttpContext.Current
msg = ""
context.Response.Clear()
context.Response.ContentType = "application/x-msexcel"
Dim b() As Byte

b = StrToByteArray(TextToAdd)
Dim lngLength As Long = b.LongLength

Try
context.Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName)
context.Response.OutputStream.Write(b, 0, lngLength)
context.Response.End()

Catch ex As Exception
msg = ex.Message
End Try

Return msg
End Function

 
If you don't know what is going on then I'm afraid we have even less chance of knowing. I'd suggest writing out some debugging information and also add some error handling.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top