SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How can i put the content of a file into a variable?

    I have tried a lot, every time my attempts end up with restarting my computer to have the IIS running again!

    So please help me

    Thanks in advance.
    Why It Doesn't Work?!

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <%@ Language=VBScript %>
    <% 
    strFileName = Server.MapPath("somefile.txt")
    Set objFS = CreateObject("Scripting.FileSystemObject")  
    Set objFile = objFS.OpenTextFile(strFileName)  
    strText = objFile.ReadAll 
    Set objFile = Nothing  
    Set objFS = Nothing
    strText = Replace(strText, vbNewLine, "<br>")
    %>
    <html>
    	<body>
    		Text from <%=strFileName%>:<br/>
    		<%=strText%>
    	</body>
    </html>


    What's the size of the file you are trying to read?

  3. #3
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JOFA... how big a file can you put into a variable like that?
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    String: Contains a variable-length string that can be up to approximately 2 billion characters in length
    VBScript Data Types
    I don't think you want to read 2 GB files...
    A 50 MB text file takes almost one minute to read

  5. #5
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had troubles with some big files I tried to concatenate. reading the entire file with the readall method and writing the var to another file.

    It just stalled... so I tried reading a line of the file and writing the line in the concatenated file like so...

    go go gadget pseudo code

    Code:
    create file called all.txt
    for each file in dir
       open the file for reading
       for each line in file
          read the line
          write the line to all.txt
       next
       close the file
    next 
    close all.txt
    and that seemed to go through a lot faster...

    well, it went through, while it bommed when I used readall.
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  6. #6
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    reading line by line is *much* more efficient than reading an entire file into a variable and then writing it all at once.
    -- JIM BOLLA
    Wanna play Halo 2? My XBOX Live gamertag: crowdozer

  7. #7
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still have the same problem

    When I try to run the code, a blanc page stay loading!!! And to have IIS running again I should open the Task Manger and end the process of something named "dllhost.exe", and hit the refresh button 2 times!!!

    Any idea?!

    Why It Doesn't Work?!

  8. #8
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any chance you have antivirus running on that computer. some antivirus software (Norton is one of the guilty parties) will cause access to the FileSystemObject to hang IIS.
    -- JIM BOLLA
    Wanna play Halo 2? My XBOX Live gamertag: crowdozer

  9. #9
    What a twist! Kings's Avatar
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    954
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, read this article about it, http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=192
    Dennis Pallett - NoCertainty - My Personal Weblog
    The Web Network: ASPit | PHPit | WebDev-Articles
    Blogs: TalkFones | Holidayzer | PHPit Blog

  10. #10
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Angry Coder
    ...something named "dllhost.exe"...
    Well, just kill the process! I don't think it's anything important

  11. #11
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    But now when I try to run jofa's code I get the fallowing error:

    Error Type:
    Microsoft VBScript runtime (0x800A003E)
    Input past end of file
    /GB/test.asp, line 6
    Why It Doesn't Work?!

  12. #12
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you get "Input past end of file" for all files, or just some of the files?
    A missing EOF in the file you are reading?

  13. #13
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The file "somefile.txt" was empty.. but when i wrote something in it everything was ok.

    Thanks a lot..
    Why It Doesn't Work?!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •