How to write to a Text File in Pipe delimited format from MS Sql Server / ASP.Net?
- by NJTechGuy
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 MS Sql 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!