• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1114
  • Last Modified:

Reading a text file in VBScript on a JSP Page

I have a JSP page, and I'd like to open a file. I've ben told this is possible using VB Script inside different tags? Has nyone experience with this? If so what would I need to do in VB script to achieve this, need to open and read a tab delimited file?
thanks
0
skellyc
Asked:
skellyc
  • 4
  • 4
  • 3
  • +1
1 Solution
 
objectsCommented:
why don't u just use java?
0
 
CodingExpertsCommented:
You want to open a client side file and display the contents/upload it. What exactly do u want to do ??

-CE
0
 
skellycAuthor Commented:
yep its a client side file which I want to open. then read the contents and upload a string to a workerbean.
re: using java. I can uplodad the whole file using a servlet and try and read data in the servlet but ..
this is specifically Word and Excel files though,  I imagine this will be easier in VB Script?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CodingExpertsCommented:
Basically, if you are looking for an utility for file upload u can see

http://jakarta.apache.org/commons/fileupload/using.html

CE
0
 
skellycAuthor Commented:
thanks I used the DiskFileUpload apache class to upload files, in a servlet etc, but therea a number of issues with doing this, I'm coming up against security and application deployment problems when saving files to the unix directory that are not eay to resolve straight away. I was rather looking therefore for a client side solution to rather parse a file locally and set up a string I can pass easily to a bean etc.....
apologies for the confusion;
0
 
CodingExpertsCommented:
You can try and set the content type

http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html

you can use ..

response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=" + "report.doc");


-CE
0
 
skellycAuthor Commented:
sorry dont know vb at all,
are there any code snippets/prewritten functions etc I can access?
On click event, Need to open a doc, parse contents the contents into a string etc..
Can I just set up new script tags with vb script on a jsp etc?

thanks
c,.
0
 
sudhakar_koundinyaCommented:
This will show a messagebox on load of html body

<html>


<Script Language=VBScript>

sub readFile
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")

vText = ""
'input text file
Set objTF = objFSO.OpenTextFile("c:\a.csv")

    do while not objTF.AtEndofStream
   
        for i = 1 to 4
            vText = vText & objTF.Readline
        next 'i

    loop
msgbox vText

Set objTF = nothing
Set objFSO = nothing

end sub
</script>

<body onLoad=readFile()>
</body>

</html>
0
 
sudhakar_koundinyaCommented:
small correction

don't need to have inner for loop

<html>
<Script Language=VBScript>
sub readFile
on error resume next

Set objFSO = CreateObject("Scripting.FileSystemObject")
vText = ""
'input text file
Set objTF = objFSO.OpenTextFile("c:\test.txt")

    do while not objTF.AtEndofStream
           vText = vText & objTF.Readline
   loop
msgbox vText

Set objTF = nothing
Set objFSO = nothing

 
end sub
</script>
<body onLoad=readFile()>
</body>

</html>
0
 
sudhakar_koundinyaCommented:
but note that

Reading the files at client side is limited to Internet Explorer only

Regards
Sudhakar
0
 
skellycAuthor Commented:
great, this does the job. I'd also like to ask how I can use the input type of file (button) to get a filepath dynamically and pass this to the function....
0
 
sudhakar_koundinyaCommented:
thanks for thne points

here is the sample as per ur requirements

<html>
<Script Language=VBScript>

function readFile (file)
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
vText = ""
'input text file
Set objTF = objFSO.OpenTextFile(file)

    do while not objTF.AtEndofStream
     vText = vText & objTF.Readline
    loop

Set objTF = nothing
Set objFSO = nothing
readFile=vText
end function

sub read_OnClick()
testform.fileholder.value=readfile( testform.testfile.value)
end sub

</script>

<body>
<form name=testform>
<P>
<input type=file name=testfile >&nbsp;&nbsp; <INPUT type=button value=read name=read></P>
<P> <INPUT style="WIDTH:
 511px; HEIGHT: 173px" size=1443 name=fileholder rows="100"
cols="100" readonly width="44" vspace=44>
</P>
</form>
</body>

</html>
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now