How can I get the sourcecode and put it in my gridview? - vb.net

On buttonclick I want to load the url from cell(0) to webwiev2-component, and then when the loading ends, I want to add the sourcecode to cell(4). The goal is to be able to preload websites from a list.
So far I have this, but it only adds System.Threading.Tasks.Task`1[System.String to cell(4) and doesnt wait for the site to load. All help is appreciated much.
Dim preuri As Uri
Dim src As String
Dim rowindex As Integer
rowindex = DataGridView1.CurrentCell.RowIndex
Try
'WebView22.Source = New Uri("https://" + DataGridView1.Rows(rowindex).Cells(0).Value.ToString)
src = WebView21.CoreWebView2.ExecuteScriptAsync("new XMLSerializer().serializeToString(document);").ToString
src = System.Text.RegularExpressions.Regex.Unescape(src)
src = src.Remove(0, 1)
src = src.Remove(src.Length - 1, 1)
DataGridView1.Rows(rowindex).Cells(4).Value = src
Catch ex As Exception
End Try
End Sub```

This answer can get you started. You'll probably want some code like:
Dim html As String
html = Await WebView2.ExecuteScriptAsync("document.documentElement.outerHTML;")
html = Regex.Unescape(html)
Note the Await bit. ExecuteScriptAsync() is an async function. It returns a Task(Of String) immediately, you need to await it to get the actual string result.

Related

Get complete host name

I want to know the full name of a remote page making an http call to my server. I am working with VB.NET and the page that is called is .ashx. At the moment I use this code snippet but I can only intercept the domain name but I don't know the exact page making the call. I've tried everything. Can you help me?
Dim _res As String = "" _hostaddress = context.Request.UserHostAddress Dim _header As NameValueCollection = context.Request.Headers _res = _header.GetValues("User-Agent").First()
Dim _res As String = "" _hostaddress = context.Request.UserHostAddress Dim _header As NameValueCollection = context.Request.Headers _res = _header.GetValues("User-Agent").First()

AxWMPlib: How to load playlist from an external file

I am making a media player application using AXWMPlib which has a playlist.
what i successfully able to do was saving the playlist items in a text file.
below is the code for saving:
If SavePlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim writefile As New System.IO.StreamWriter(SavePlaylist.FileName)
For i = 0 To lstview.Items.Count - 2
writefile.WriteLine(Form1.main.AxWMP1.currentPlaylist.Item(i).sourceURL)
Next
writefile.Write(Form1.main.AxWMP1.currentPlaylist.Item(Form1.main.AxWMP1.currentPlaylist.count - 1).sourceURL)
writefile.Close()
End If
for loading i wrote till here:
If OpenPlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim readfile As New System.IO.StreamReader(OpenPlaylist.FileName)
Dim ob As String = readfile.ReadToEnd()
Dim content() As String = OpenPlaylist.FileName.Split(Environment.NewLine)
End If
i dont know how to read the lines stored in current() and append them in current playlist.
found a solution:
If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim readfile As New System.IO.StreamReader(Open.FileName)
Dim ob As String = readfile.ReadToEnd()
Dim content() As String = ob.Split(Environment.NewLine)
For Each Line As String In content
Dim item As IWMPMedia = Form1.AxWMP1.newMedia(Line)
Form1.AxWMP1.currentPlaylist.appendItem(item)
Next
End If

test if a folder exist or not in google drive

I want to know if folder (subfolder) exist in google drive or not , after searching in this page , i try to do it , i create a boolean function which return true if folder exist .
here is a code of boolean function
Public Function exist(v As String) As Boolean
Dim pag As String
Dim req = Service.Files.List()
req.Q = "application/vnd.google-apps.folder"
req.PageToken = pag
Dim result = req.Execute()
If (result.NextPageToken IsNot Nothing) Then
Return False
Else
Return True
End If
End Function
and here how i call it
If (exist(dat_sauv.SelectedItem) = False) Then
MessageBox.Show("folder exist")
End If
the exception is
exception has declenched in exist method in this insctruction
Dim result = req.Execute()
is my method correct or not ? can you help me
There are two problems with your code.
Improper query
Your line req.Q = "application/vnd.google-apps.folder"
should be
req.Q = "mimeType='application/vnd.google-apps.folder' and name = '"+v+"' and trashed=false"
You'll probably need to tidy up the quoting and escaping (ie Don't copy/paste and expect it to work first time)
use of nextPageToken
The presence of the folder will not be indicated by the presence of nextpageToken. Instead, you need to check the files array within the response for >0 elements.

Error with UltraID3Lib VB

Well I get this error (The ID3v2TagVersions value of '4' (4) is not valid for this operation.) with UltraID3Lib on Visual Basic 2013. I want to use this library (dll) so i can edit my mp3 tags in a mp3 file. Although I achived changing the tags , when i use the Clear() sub and then retry to change the tags i get this error. Can anyone help me ?
My Code
Private Sub btnExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim Artist As String = ""
Dim Title As String = ""
Dim MP3TagEditor As New UltraID3
For Each Path In MP3List
MP3TagEditor.Read(Path)
Title = "Somthing"
Artist = "Somthing"
MP3TagEditor.ID3v2Tag.Title = Title
MP3TagEditor.ID3v2Tag.Artist = Artist
MP3TagEditor.Clear()
MP3TagEditor.Write()
Next
MsgBox("Tags Added", MsgBoxStyle.Information, "Success")
End Sub
Thanks
Try this
Dim sTitle As String = "No Name"
Dim sSinger As String = ""
Dim sAlbum As String = ""
Dim sYear As String = ""
Dim sComm As String = ""
Dim MP3Tag As New UltraID3
MP3Tag.Read(YOUR_PATH)
Try
Dim pics = MP3Tag.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture)
AlbumPic.Image = CType(pics(0), ID3v2PictureFrame).Picture
Catch ex As Exception
AlbumPic.Image = My.Resources.FlatCD
End Try
Try
sTitle = MP3Tag.Title
sSinger = MP3Tag.Artist
sAlbum = MP3Tag.Album
Catch ex As Exception
End Try
You cannot read ID3v2.4 tags from an MP3 file with UltraID3Lib. It doesn't support it yet. (As of 31/12/2015).
But there is an alternative, which, in my humble opinion is even better, stable and efficacious:
TagLib-Sharp
It supports many other tag types as well apart from ID3, i.e, MP3 Files.
A quick example to get you on the way:
Dim f As TagLib.File = TagLib.File.Create("someFile.mp3")
Dim artist As String = f.Tag.JoinedPerformers
Dim title As String = f.Tag.Title
More resources for TagLib-Sharp:
Where can I find tag lib sharp examples?
Set Bitmap as cover art for MP3

VB - Issue using XPath reading an XML

I am currently trying to read in an XML node from a filepath which I pass to my method.
Public Function ReadXMLForIsite(xmlFileName As String)
Dim IsitePath As String
Dim doc As New XPathDocument(xmlFileName)
Dim nav As XPathNavigator
Dim iter As XPathNodeIterator
nav = doc.CreateNavigator
iter = nav.Select("GovTalkMessage/Header") 'Node name
'Loop through the records in that node
While iter.MoveNext
Dim lstNav As XPathNavigator
'Get the data we need from the node
Dim iterNews As XPathNodeIterator
lstNav = iter.Current
iterNews = lstNav.SelectDescendants(XPathNodeType.Element, False)
'Loop through the child nodes
While iterNews.MoveNext
Debug.WriteLine(iterNews.Current.Name & ": " & iterNews.Current.Value)
End While
End While
Return IsitePath
End Function
Every time i run this method (even with different node names) the variable 'iter' states that 'debugger display proxy is a type and cannot be used as an expression'. This occurs just before the while statement, therefore does not go in. Any help would be much appreciated. Thanks!
Try to load your Xml into an XDocument.
Dim xdoc As XDocument = XDocument.Load("X:\Jacob.Freeman\RTI\TestXML\0001R.xml")
Dim headerNode = xdoc.Descendants.First(Function(x) x.Name.LocalName = "Header")
For Each desc In headerNode.Descendants()
Console.WriteLine(desc.Name.LocalName + ":" + desc.Value)
Next
Console.ReadLine()