How to write to a text file in pipe delimited format from SQL Server / ASP.Net?

Posted by NJTechGuy on Stack Overflow See other posts from Stack Overflow or by NJTechGuy
Published on 2010-03-19T04:42:07Z Indexed on 2010/03/19 6:51 UTC
Read the original article Hit count: 227

I have a text file which needs to be constantly updated (regular intervals).

All I want is the syntax and possibly some code that outputs data from a SQL Server database using ASP.Net. The code I have so far is :

<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
  sub Page_Load(sender as Object, e as EventArgs)
  Dim FILENAME as String = Server.MapPath("Output.txt")

    Dim objStreamWriter as StreamWriter
   ' If Len(Dir$(FILENAME)) > 0 Then Kill(FILENAME)
   objStreamWriter = File.AppendText(FILENAME)

    objStreamWriter.WriteLine("A user viewed this demo at: " & DateTime.Now.ToString())

    objStreamWriter.Close()

    Dim objStreamReader as StreamReader
    objStreamReader = File.OpenText(FILENAME)

    Dim contents as String = objStreamReader.ReadToEnd()

    lblNicerOutput.Text = contents.Replace(vbCrLf, "<br>")

    objStreamReader.Close()
  end sub
</script>

<asp:label runat="server" id="lblNicerOutput" Font-Name="Verdana" />

With PHP, it is a breeze, but with .Net I have no clue. If you could help me with the database connectivity and how to write the data in pipe delimited format to an Output.txt file, that had be awesome. Thanks guys!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql-server