Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear all,

 

I am new to Vb. Now i am finding a method to read a file on server through internet by VB.net. Just like OPEN(file, ">file.txt"); by perl. How can I do like this? Use system.net? Can anybody give me some help. Thanks a million.

 

NoriCat

  • *Experts*
Posted

You can use the WebClient class in the System.Net namespace to

download files and read streams from files.

 

Use the DownloadFile method to download a file (duh :)).

Use the OpenRead method to open the remote file as a stream,

which you can then read into a string by creating a StreamReader

and then ReadToEnd.

 

Here's an example of downloading a remote file to a string:

Dim sData As String
Dim stream As IO.StreamReader
Dm wc As New Net.WebClient()

stream = New IO.StreamReader(wc.OpenRead("file URL here"))

sData = stream.ReadToEnd

 

I use the above method all the time when downloading HTML to

parse through it.

 

HTH

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Guest noricat
Posted

If I want to delete that file, what class and method should I use? :confused:

I tried IO.File.delete, but failed :(

It seems must connected to the server first.:confused:

  • *Experts*
Posted

Delete what file? If you're using the code example I mentioned,

there is no file created; a stream is created to read from, which is

only temporary.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Guest noricat
Posted
Delete the file "file.txt". I read the file successfully by using your method StreamReader [(wc.OpenRead("http://www.xxx.com/file.txt"))] :). After read, I want to delete it immediately. I think my program should access the server so can receive the permission to delete the file. But what class and method should I use. I search for a few days...but still didnt find it.:( :( :(
  • 1 month later...
Guest jefftheman812
Posted

Does anyone know how to accomplish this same task with VB 6 ?

Just to reiterate, I need to grab the title of a Internet based web page.

I really do not wish to download the entire file, I would love to "open a stream to it", I saw the example but do not recall anything like that in VB 6.

 

I have VS.net, but have not installed it yet, I would probably be lost in it and would prefer to stick to vs6 at this time.

 

Any help much appreciated !:)

Guest jefftheman812
Posted
Wow, I guess the advice I needed was really simple :-)
  • 6 months later...
Posted

I hate to bring up a dead topic, but I'm a newbie to VB.Net and was wondering, once you've got the string, how'd I go about reading the contents line by line, like an ini file, for example:

 

[user]

SomeInfoHere

 

[Pass]

SomeMoreInfoHere

 

How'd I be able to read [user] as a value, being "SomeInfoHere" and [Pass] as "SomeMoreInfoHere " ? Thanks...

Posted (edited)

Look into class Regex or do a char by char search with a loop.

string word="[House]";
bool match=false;
int matchIndex = -1;
for(int i=0; i < MySearchDocument.Length; i++)
{
    if ( MySearchDocument[i] == "[" )
    {
        for(int h=1; h < word.Length; h++)
         {
              if(word[i]==MySearchDocument[i+h])
               {
                 match=true;
               }
              else match=false;
         }
     }
      if(match)
      {
          //You have what you were looking for.
          break;  //Break out of the nested loop.
      }
}

I did not test this but I hope you get the idea. If you cannot read C# at all there are some translators on the internet that allow you to paste code in a text box to see it in VB.

Edited by aewarnick
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...