Re: writing a file locally using response.write

Discussion in 'ASP .Net' started by bruce barker, Dec 9, 2008.

  1. bruce barker

    bruce barker Guest

    no, you just get to specify the default name in the header.

    -- bruce (sqlwork.com)

    wrote:
    > I use this code stuff a table into a data adapter and then output to Excel.
    > Is there a way when I write the file, I can hard code the path? The path will be on the client.
    >
    > Try
    > Dim cnn As New Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings.Get("mcnn"))
    > Dim da As New SqlClient.SqlDataAdapter
    > Dim ds As New DataSet
    > Dim cmd As New SqlClient.SqlCommand
    > Dim stringWrite As New System.IO.StringWriter
    > Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
    > Dim dg As New DataGrid
    >
    > cmd.Connection = cnn
    > da.SelectCommand = cmd
    > cmd.CommandText = lSql
    > da.Fill(ds, "Anyvalue")
    > Response.Clear()
    > Response.Charset = ""
    > Response.AddHeader("Content-disposition", attachment;filename=EmployeeExport")
    > Response.ContentType = "application/vnd.ms-excel"
    >
    >
    > dg.DataSource = ds.Tables("Anyvalue")
    > dg.DataBind()
    > dg.RenderControl(htmlWrite)
    > Response.Write(stringWrite.ToString)
    > Response.End()
    > cnn.Close()
    > Catch ex As Exception
    > tb1.Text = ex.Message
    >
    >
    > End Try
    >
    >
    >
    >
    >
     
    bruce barker, Dec 9, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    2
    Views:
    8,099
    Charles A. Lackman
    Jan 11, 2006
  2. Matthew Wieder

    Response.Write and Response.Redirect

    Matthew Wieder, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    760
    Kevin Spencer
    Jul 17, 2003
  3. Sehboo
    Replies:
    3
    Views:
    8,940
    Sehboo
    Dec 10, 2003
  4. Peter A. Schott
    Replies:
    0
    Views:
    929
    Peter A. Schott
    Feb 10, 2005
  5. Replies:
    1
    Views:
    867
Loading...

Share This Page