Solved

Visual Basic FileSystemObject reading from http

Posted on 2003-11-04
17
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
17 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9681472
Filesystemobject is not created to do that.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9682359
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
ID: 9683099
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683590
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
ID: 9686816
I like the last comment from fantasy1001
0
 

Author Comment

by:pryal
ID: 9688753
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
ID: 9688810
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
 
LVL 3

Expert Comment

by:tonydspaniard
ID: 9689657
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
ID: 9691531
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
ID: 9698347
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
ID: 9698366
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
ID: 9707832
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
ID: 9711712
As far as I know, that will work for you.
0
 

Author Comment

by:pryal
ID: 9711727
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
ID: 10479032
Meant to try and split points but not sure how to?

Thanks
-Simeon
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month6 days, left to enroll

626 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