Sunday, April 12, 2009

Save a CSV File in Browser

Private Sub lbCSVTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbCSVTemplate.Click

If File.Exists(Server.MapPath("~/CSVUploaded/template.csv")) Then

Response.ContentType = "text/csv"

'Some browsers open the file directly in browser, so this will cause a file "Save as" dialogue to appear.

Response.AppendHeader("Content-Disposition", "attachment; filename=template.csv")

Response.TransmitFile(Server.MapPath("~/CSVUploaded/template.csv"))

Response.End()

Else

lblMsg.Text = MessagesDAL.Instance.Get_MessageByID(Messages.MessageCodes.CSVTemplateNotAvailable)

lblMsg.ForeColor = Drawing.Color.Red

End If

End Sub

Reference:
Downloading a File with a Save As Dialog in ASP.NET

blog comments powered by Disqus