Guest noricat Posted September 30, 2002 Posted September 30, 2002 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 Quote
*Experts* Bucky Posted September 30, 2002 *Experts* Posted September 30, 2002 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 Quote "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 October 4, 2002 Posted October 4, 2002 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: Quote
*Gurus* divil Posted October 8, 2002 *Gurus* Posted October 8, 2002 File.Delete should work, it would help if you told us what error that gives you. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Bucky Posted October 8, 2002 *Experts* Posted October 8, 2002 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. Quote "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 October 9, 2002 Posted October 9, 2002 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.:( :( :( Quote
*Gurus* divil Posted October 9, 2002 *Gurus* Posted October 9, 2002 It's not going to be that easy to delete a file from a webserver! You'll have to go in via FTP, probably. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest noricat Posted October 11, 2002 Posted October 11, 2002 I SEE...:( Anyway~thanks a lot ;) Quote
Guest jefftheman812 Posted November 13, 2002 Posted November 13, 2002 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 !:) Quote
*Gurus* Derek Stone Posted November 13, 2002 *Gurus* Posted November 13, 2002 This is the VB.NET board. Post your Visual Basic 6 questions in the Visual Basic board. Quote Posting Guidelines
Guest jefftheman812 Posted November 14, 2002 Posted November 14, 2002 Wow, I guess the advice I needed was really simple :-) Quote
DaveHope Posted May 26, 2003 Posted May 26, 2003 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... Quote
Moderators Robby Posted May 26, 2003 Moderators Posted May 26, 2003 You wouldn't read it line-by-line, you will read the entire content using ReadToEnd, then you will need to parse whatever the string's value is yourself. Quote Visit...Bassic Software
DaveHope Posted May 26, 2003 Posted May 26, 2003 Thanks, say the content is: MyInfo MyInfo2 How'd i do something like: IF Line1 = "MyInfo" then... End IF Thanks very, very much. Quote
aewarnick Posted June 2, 2003 Posted June 2, 2003 (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 June 2, 2003 by aewarnick Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.