reading text file in ASP
There is a fixed width text file , on each line of the text file i have to check on column 256&257 for blanks.
Is somebody have any idea, how to do this in ASP
I have been using FSO in ASP , but so far not able to access a particular column in every line.
HELP NEEDED URGENT!!!
[294 byte] By [
aasis10] at [2007-11-11 10:11:42]

# 1 Re: reading text file in ASP
Do you know how to read each line of the file into a string variable? Once you have a line in the string, you can use the Mid() function to examine columns 256 & 257:
Temp = Mid(theLine, 256, 2)
If Temp = " " Then...
# 2 Re: reading text file in ASP
Thanks for you quick reply ..seems to working now ...thanks
# 3 Re: reading text file in ASP
i have written the following code in ASP ..
how to convert it automatically in ASP.NET ?
i have tried changing the code but it is giving me erros .
code is:
<% Option Explicit
Const Filename = "/AGC-20070102-UPT.txt" ' file to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")
' Map the logical path to the physical system path
Dim Filepath
Filepath = "//mu-bfs/manu/general/valProviderAddress/AGC-20070102-UPT.txt"
if FSO.FileExists(Filepath) Then
' Get a handle to the file
Dim file
set file = FSO.GetFile(Filepath)
' Get some info about the file
Dim FileSize
FileSize = file.Size
Response.Write "<p><b>File: " & Filename & " (size " & FileSize &_
" bytes)</b></p><hr>"
Response.Write "<pre>"
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading, _
TristateFalse)
' Read the file line by line
Do While Not TextStream.AtEndOfStream
Dim Line,Temp
Line = TextStream.readline
Temp = Mid(Line, 329, 2)
if trim(Temp) <> "" then
response.Write ("fine")
end if
Loop
Response.Write "</pre><hr>"
Set TextStream = nothing
Else
Response.Write "<h3><i><font color=red> File " & Filename &_
" does not exist</font></i></h3>"
End If
Set FSO = nothing
%>
</PRE>
</body>
</html>
any help will be much appreciated...
# 4 Re: reading text file in ASP
I don't know of any way to automatically convert VBScript to VB.NET. Here is the VB.NET equivalent of the above code:
Imports System.IO
Const FileName As String = "/AGC-20070102-UPT.txt"
Dim FilePath As String = "//mu-bfs/manu/general/valProviderAddress" & FileName
If File.Exists(FilePath) Then
' Get a handle to the file
Dim file As New FileInfo(FilePath)
' Get some info about the file
Dim FileSize As Long = file.Length
Response.Write "<p><b>File: " & FileName & " (size " & FileSize & " bytes)</b></p><hr>"
Response.Write("<pre>")
' Open the file
Dim reader As TextReader
reader = file.OpenText()
' Read the file line by line
Dim Line As String
Do
Line = reader.ReadLine
If Mid(Line, 329, 2) <> " " Then
Response.Write("fine")
End If
Loop Until Line Is Nothing
Response.Write("</pre><hr>")
reader.Close()
Else
Response.Write "<h3><i><font color=red> File " & FileName & " does not exist</font></i></h3>"
End If
# 5 Re: reading text file in ASP
Phil i have tried to execute the vb.net but it is giving me the following error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'File' is not declared.
Source Error:
Line 5: Dim FilePath As String = "//mu-bfs/manu/general/valProviderAddress" & FileName
Line 6:
Line 7: If File.Exists(FilePath) Then
Line 8: ' Get a handle to the file
Line 9: Dim file As New FileInfo(FilePath)
Source File: C:\Inetpub\Site\contentmu\vrprovider\vladdress.aspx Line: 7
# 6 Re: reading text file in ASP
You must include the line "Imports System.IO" at the top of your code file.
# 7 Re: reading text file in ASP
I have already done that , code is :
Imports System.IO
<%
Const FileName As String = "/AGC-20070102-UPT.txt"
Dim FilePath As String = "//mu-bfs/manu/general/valProviderAddress" & FileName
If File.Exists(FilePath) Then
' Get a handle to the file
Dim file As New FileInfo(FilePath)
' Get some info about the file
Dim FileSize As Long = file.Length
Response.Write "<p><b>File: " & FileName & " (size " & FileSize & " bytes)</b></p><hr>"
Response.Write("<pre>")
' Open the file
Dim reader As TextReader
reader = file.OpenText()
' Read the file line by line
Dim Line As String
Do
Line = reader.ReadLine
If Mid(Line, 329, 2) <> " " Then
Response.Write("fine")
End If
Loop Until Line Is Nothing
Response.Write("</pre><hr>")
reader.Close()
Else
Response.Write "<h3><i><font color=red> File " & FileName & " does not exist</font></i></h3>"
End if%>
# 8 Re: reading text file in ASP
Try this:
<% @Import Namespace="System.IO" %>
<%
Const FileName As String = "/AGC-20070102-UPT.txt"
Dim FilePath As String = "//mu-bfs/manu/general/valProviderAddress" & FileName
' etc.
# 9 Re: reading text file in ASP
I have done that changes , now i am getting the following error
Server Error in '/Site' Application.
------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30800: Method arguments must be enclosed in parentheses.
Source Error:
Line 12: Dim FileSize As Long = file.Length
Line 13:
Line 14: Response.Write "<p><b>File: " & FileName & " (size " & FileSize & " bytes)</b></p><hr>"
Line 15: Response.Write("<pre>")
Line 16:
Source File: C:\Inetpub\Site\contentmu\vrprovider\vladdress.aspx Line: 14