Solved

Visual Basic FileSystemObject reading from http

Posted on 2003-11-04
17
627 Views
Last Modified: 2013-11-25
Hello,
  I have a program setup that currently reads a passwords.dat file that contains passwords and stores them in an array. I also have this file located at an http:// address and want to read from an http address instead of from my local hard drive. When I switch the path name for the fileexists command, it returns false if I have an http:// address. How can I get this to work?

Thanks
-Simeon

0
Comment
Question by:pryal
  • 5
  • 4
  • 2
  • +2
17 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Filesystemobject is not created to do that.
0
 
LVL 3

Expert Comment

by:NBrownoh
Comment Utility
use the windows internet transfer control then do something like this:

t = Inet1.OpenURL("http://www.yoururl.com/passwordfile.dat")

t now contains everything that your online password file contains
0
 
LVL 3

Expert Comment

by:tonydspaniard
Comment Utility
Hi there,
You can also use XMLHTTP Objects for that 'instead of using createobject you better make a reference to the libraries!'

Private Function getResult(URL, strMethod) As Variant

      'Dimension variables
      Dim objXMLHTTP                  'Holds the XML HTTP Object
      Dim strResultString                                      'Holds the reult of the query

      'Create an XML object to query the remote whois server
      Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
      
      'Alternative XML HTTP component, for version 3.0 of XMLHTTP
        'Set objXMLHTTP =CreateObject("MSXML2.ServerXMLHTTP")

      'Open a connection to the remote server
        objXMLHTTP.Open strMethod, URL, False
       
        'Send the request and return the data
        objXMLHTTP.Send
       
        'Place the registry response into the result string
        strResultString = objXMLHTTP.ResponseText
       
       
        'If the domain name is to short then tell them it's invalid
        If InStr(1, strWhoisResultString, "Error", vbTextCompare) Then
              
              'Set the return result of the function to Taken
              getResult = "An Error has occured"
              
        'Else there was a result
        Else
              
              ' Do whatever with the data
                 getResult = strResultString
        End If
       
        'Clean up
        Set objXMLHTTP = Nothing
End Function


Regards and Good Luck
0
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
Add Microsoft HTML Object Library component, donn't need to add to form. also add a textbox

    Dim objMSHTML As New HTMLDocument
    Dim objDoc As HTMLDocument
    Set objDoc = objMSHTML.createDocumentFromUrl("http://www.mysite.com/passwords.dat", vbNullString)
   
    While objDoc.readyState <> "complete"
        DoEvents
    Wend

    text1.text = objDoc.documentelement.innertext

~ fantasy ~
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
I like the last comment from fantasy1001
0
 

Author Comment

by:pryal
Comment Utility
Hello Again,
  Thanks a ton for your responses, it helps out a lot!!! The only other thing I forgot to mention is that I need to be able to write back to this file from my vb program. I am going to take the some information that I have in a text box and add it to the file. I will create an array, and store the file in an array. But I need to be able to read the file into the array LINE BY LINE. Then I will take this information I have in the text box, search the array and put it into the array at the apporiate point. Once I have this array updated then I need to be able to read the array and write it back to file. Do you know how I could accomplish this?

Thanks AGAIN
-Simeon
0
 
LVL 3

Expert Comment

by:NBrownoh
Comment Utility
so you just want to do this
open the file
load it into an array
check array entries against a text box
?if the entry checks out? load it into the array
save array back into file on server

right?  the only thing i dont understand is on what condition will you be inserting something into the array?
and how is your current file being delimeted? by line returns?  spaces?  some character?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:tonydspaniard
Comment Utility
Well you can do that with API (http://www.vb2themax.com/HtmlDoc.asp?Table=Articles&ID=520) with FTP, Socket control, and/or  internet transfer control (http://www.juicystudio.com/tutorial/vb/http.asp)

READ THE ARTICLES AND CHECK PSEUDOCODE -WITH INET TRANSFER CONTROL:

SET INET PROPERTIES (USERNAME-PWD-URL-PROTOCOL)
CONNECT
CONNECTION OK? NO-->DISPLAY ERROR MSG
YES
REQUEST PAGE
REQUEST OK? NO-->DISPLAY ERROR MSG
YES
INIT FILESYSTEMOBJECT
SAVE FILE TO DISK (?-- YOU SAID YOU WANT TO READ IT LINE BY LINE... THEN USE FILESYSTEMOBJECT FOR THAT)
READ FILE FROM DISK
CHECK LINE BY LINE DOCUMENT
CHANGES DONE
SAVE FILE OVERWRITING OLD ONE
SET FILESYSTEMOBJECT TO NOTHING
INET EXECUTES FTP PUT COMMAND TO UPLOAD FILE
SET INET TO NOTHING

Hope this helps Good Luck
0
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
Aswering your request, if you use mshtml method and load the file into a text box, then

1. To load into an Array

    Dim myAry() As String
    myAry = Split(Text1.Text, vbCrLf)

    'manipulate your array here

    open "c:\passwords.dat" for output as #1
       'Loop through array and print to file
       dim str as string
       for each str in myAry
          print #1, str   'add vbcrlf if want new line
       next
    close #1

Now, you will have your modified file saved in c:\passwords.dat
You need to upload your file to the server with http or ftp

check out the comment from bruintje
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=n5aV1d2yCHA.3028%40cpmsftngxa06

You can use XMLHTTP with PUT method to upload the file, following is the
sample code:

Private Sub Command1_Click()
     strFName = "c:\test.txt"
     strShortFName = Right(strFName, Len(strFName) - InStrRev(strFName,
"\"))
     Set stmFile = CreateObject("ADODB.Stream")
     stmFile.open
     stmFile.Type = 1
     stmFile.LoadFromFile strFName
     Set oXH = CreateObject("MSXML2.XMLHTTP")

     oXH.open "PUT", "http://<your web server>/" & strShortFName, False
     oXH.setRequestHeader "Translate", "f"
     
     oXH.send stmFile.Read()
        If oXH.Status = 200 Then
            MsgBox "transfer complete!"
        Else
            MsgBox "Error " & oXH.Status
        End If
     Set oXH = Nothing
     Set stmFile = Nothing
End Sub

Please note that you need to allow write permission for your Virtual
Folder, as well as check if the anonymous user has NTFS write permission to
the physical folder.

NOTEL: you will need to delete the original or overwrite it

~ fantasy ~
0
 

Author Comment

by:pryal
Comment Utility
Hello,
  Thanks a bunch for the help. I have the program working for the most part except a few things... In my html file I am using 2 tags :
<div>
and
<img src="sourcelink">

The problem is that DIV and IMG are reserved by Visual Basic so it does not like to read this part of the html file into the array, is there any way to get around this?? Can I tell vb to ignore the reserved variable DIV and  IMG so that I can use it, or is there another way around it?

Thanks SO MUCH, its seems so close to working!
-Simeon
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
Comment Utility
Do you mean the passwords file is in the html file format?
If so, you should have use this method instead,

    Dim objMSHTML As New HTMLDocument
    Dim objDoc As HTMLDocument
    Set objDoc = objMSHTML.createDocumentFromUrl("http://www.mysite.com/passwords.dat", vbNullString)
   
    While objDoc.readyState <> "complete"
        DoEvents
    Wend

with this, we can insert text at whatever location we want, using insertadjacenttext and many more function.

About the div and img, I donn't think we cannot read it into an array from a html file. How did you read the html file anyway?
0
 

Author Comment

by:pryal
Comment Utility
Hello,
  Thanks again for the reply!!!!! Actually, I was mistaken - the DIV and IMG thing is not a problem. But I like your coding you gave me, because that seems more efficient than what I am doing. To answer your question, I am reading the html file by downloading the file to the local hard disk, and then reading it using a FileSystemObject into an array!! I will try the code out that you gave me! If I have a statement as follows:

HTMLCodeArray(3).line = " html code goes here"

Now this will work, but what if the Html code I want to put into the array is the following:

<p style="text-align: center; font-size: 110%;">

The HTML code string above has quotes in it, will this work considering that the assigment statement begins and ends with quotes? If not, is there a way around it?

THANKS AGAIN!
-Simeon
0
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
As far as I know, that will work for you.
0
 

Author Comment

by:pryal
Comment Utility
Hello,
   Great, I will try this out and hopefully have succesffully made this program work!! I greatly appreciate everyones help!

Thanks Again,
Simeon
0
 

Author Comment

by:pryal
Comment Utility
Meant to try and split points but not sure how to?

Thanks
-Simeon
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now