none
Search a text under a URL RRS feed

  • Question

  • Hi,

    I am using the System.IO to read from a file /folder to check if a desired text is available or not, something below:

    System.IO.File.ReadAllText("C:\MyDir\MyFile.txt").Contains("TempText") Then ....

    But is it possible to check for a URL / link to google or OneDrive folder? for example: https://www.MyCloud.com\mySharedFolder

    if yes, please suggest an example, thanks.

    Wednesday, February 5, 2020 9:03 AM

Answers

  • Hi,

    You can use the WebRequest.Create method to initialize a new HttpWebRequest object. Then get the URL page content and write it to the stream object.

    Please refer to my code below.

    Imports System.IO
    Imports System.Net
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim url As String = “https://social.msdn.microsoft.com/Forums/vstudio/en-US/d46e1b0a-293c-4430-ac22-1109ce0195ea/search-a-text-under-a-url?forum=vbgeneral”
            Dim uri As Uri = New Uri(url)
            'Create an instance of access to a URL
            Dim req As WebRequest = WebRequest.Create(uri)
            'Return the response from the Internet resource.
            Dim resp As WebResponse = req.GetResponse()
            'Get the Stream object used to write the requested data.
            Dim stream As Stream = resp.GetResponseStream()
            'when accessing IO resources, use using to ensure normal operation
            Using sr = New StreamReader(stream)
                Dim str As String = sr.ReadToEnd()
                If str.Contains("Search a text under a URL") Then
                    MsgBox("Yes")
                Else
                    MsgBox("No")
                End If
            End Using
    
        End Sub
    End Class
    

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by -OSD- Thursday, February 6, 2020 11:22 AM
    Thursday, February 6, 2020 1:50 AM
    Moderator

All replies

  • Hi,

    You can use the WebRequest.Create method to initialize a new HttpWebRequest object. Then get the URL page content and write it to the stream object.

    Please refer to my code below.

    Imports System.IO
    Imports System.Net
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim url As String = “https://social.msdn.microsoft.com/Forums/vstudio/en-US/d46e1b0a-293c-4430-ac22-1109ce0195ea/search-a-text-under-a-url?forum=vbgeneral”
            Dim uri As Uri = New Uri(url)
            'Create an instance of access to a URL
            Dim req As WebRequest = WebRequest.Create(uri)
            'Return the response from the Internet resource.
            Dim resp As WebResponse = req.GetResponse()
            'Get the Stream object used to write the requested data.
            Dim stream As Stream = resp.GetResponseStream()
            'when accessing IO resources, use using to ensure normal operation
            Using sr = New StreamReader(stream)
                Dim str As String = sr.ReadToEnd()
                If str.Contains("Search a text under a URL") Then
                    MsgBox("Yes")
                Else
                    MsgBox("No")
                End If
            End Using
    
        End Sub
    End Class
    

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by -OSD- Thursday, February 6, 2020 11:22 AM
    Thursday, February 6, 2020 1:50 AM
    Moderator
  • Thanks Julie, it does exactly what is I was looking for, thanks for sharing.
    Thursday, February 6, 2020 11:23 AM
  • To add further beauty, is it possible to copy a file to the above specified URL ?

    What I did didn't worked as:

    FileSystem.FileCopy("C:\Temp.txt", "url")

    • Edited by -OSD- Thursday, February 6, 2020 11:33 AM
    Thursday, February 6, 2020 11:27 AM