I'm having issue to retrive thumb from metacafe video id.
The problem is that even the url seems to be correct (after opening source html) but when we change the new ID in the same URL it will return 400 error page.
Here is the working url:
http://cdn.mcstatic.com/contents/videos_screenshots/11827000/11827430/preview.jpg
Here is not working url:
http://cdn.mcstatic.com/contents/videos_screenshots/11826998/11826998/preview.jpg
Seems like really crazy that even the wrong URL contains same direct thumb link but when type it will get 404 not found.
I hope someone could solve this mystery.
Public Sub getThumb()
Dim thumbURL As String = "http://cdn.mcstatic.com/contents/videos_screenshots/"
Dim videoID As String = "1827000"
PreviewBox.ImageLocation = (thumbURL + videoID + "/" + videoID + "/preview.jpg")
End Sub
After some external help from someone I get this done.
I hope it will help someone.
Public Sub getThumb()
Dim thumbURL As String = "http://cdn.mcstatic.com/contents/videos_screenshots/"
Dim videoID As String = "1827000"
PreviewBox.ImageLocation = (thumbURL + videoID.Remove(videoID.Length - 3) + "000/" + videoID + "/preview.jpg")
End Sub
Related
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.
ok im going to try to explain this the best i can.
So i have a list viewer for image thumbnails.
I need to be able to click a button and it load the full dir. The issue is the normal way loads the images in but they are out of order. 1.jpg 10.jpg 100.jpg
For Each file As String In My.Computer.FileSystem.GetFiles(appPath + "\" + ConfigurationManager.AppSettings("activedisplay").ToString + "\" + Bfolder.Text + "\")
ImageListView1.Items.Add(file)
Next
So i went and looked around for a filter
Dim files = Directory.EnumerateFiles(appPath + "\" + ConfigurationManager.AppSettings("activedisplay").ToString + "\" + Bfolder.Text + "\").
Select(Function(s) Path.GetFileName(s)).ToList
Console.WriteLine("Before: {0}", String.Join(", ", files))
' sort the list using the Natural Comparer:
files.Sort(myComparer)
MsgBox((String.Join(", ", files)))
So this script puts them in the right order 1,2,3,4,5.. but i cant figure out how to open it this way. Cause
ImageListViewer1.items.addrange((String.Join(", ", files)))
overloads.
Like openFileDialog.FileNames has the ability to open multiple files at once so I know its possible but i don't want to use a dialog.
To the point i need a way to load the file string produced by this which is 1.jpg,2.jpg,3.jpg into the ImageViewerList.
This creates a string of the file in the correct order "(String.Join(", ", files))" is there a way i can load files from a string.
For Each file As String In My.Computer.FileSystem.GetFiles(appPath, string
and it be able to load the string of files it creates the string like so
1.jpg,2.jpg,3.jpg continued for all files in the dir it looked at
iv looked around google for assistance and looked at the ms page on getfiles but i have had no luck.
any ways any help would be greatly appreciated
thanks in advance
-Fox
You need to write your own sort function to sort the numeric values.
I referred the link, for CustomSort function. Below code sorts the file names and works nicely for me.
Dim Dir As String = appPath + "\" + ConfigurationManager.AppSettings("activedisplay").ToString + "\" + Bfolder.Text + "\"
Dim fileList = New DirectoryInfo(Dir).GetFiles("*.jpg").[Select](Function(o) o.Name).ToList()
Dim sortedList = CustomSort(fileList).ToList()
Public Shared Function CustomSort(list As IEnumerable(Of String)) As IEnumerable(Of String)
Dim maxLen As Integer = list.[Select](Function(s) s.Length).Max()
Return list.[Select](Function(s) New With { _
Key .OrgStr = s, _
Key .SortStr = Regex.Replace(s, "(\d+)|(\D+)", Function(m) m.Value.PadLeft(maxLen, If(Char.IsDigit(m.Value(0)), " "c, "?"c))) _
}).OrderBy(Function(x) x.SortStr).[Select](Function(x) x.OrgStr)
End Function
I have a string in VB:
url = "http://example.com/aa/bb/cc.html"
I want to trim this url to the last sub-folder so it becomes:
url = "http://example.com/aa/bb"
I need everything after the last "/" to be removed.
I am thinking of using the string.lastindexof("/") method but don't know how to continue from there.
use a combination of Substring and Lastindex of. Like this:
url.substring(0,url.lastindexof("/"))
might be that you need to substract 1 from the lastindexof("/") value, i always forget it^^
When working with an URL, consider using the Uri class. Then handling such cases become easy.
Create a Uri instance:
Dim url = new Uri("http://example.com/aa/bb/cc.html")
Then you can either do
Dim result = url.AbsoluteUri.Remove(url.AbsoluteUri.Length - url.Segments.Last().Length)
or something like
Dim result = new Uri(url, ".").AbsoluteUri
You could use String.Remove() to remove the unwanted part of the string:
Dim temp As String = "http://example.com/aa/bb/cc.html"
Dim index As String = temp.LastIndexOf("/"c)
Dim ret As String = temp.Remove(index, temp.Length - index)
This works fine:
Dim ADEntry = New DirectoryEntry(ldapPath + userName, au, ap)
Dim Name = ADEntry.Properties("FullName").Value.ToString()
Return Name
But this does not:
Dim ADEntry = New DirectoryEntry(ldapPath + userName, au, ap)
Dim firstName = ADEntry.Properties("givenName").Value.ToString()
Dim lastName = ADEntry.Properties("sn").Value.ToString()
Return firstName + " " + lastName
I also tried using ADEntry.Properties("givenName")(0).Value.ToString() as I read somewhere they may be indexed. I got the same result, "Object reference not set to instance of an object".
Those are indeed both indexed properties, and the way you're accessing them looks fine to me.
As a good practice though, you should check to make sure there is actually a value associated with this property before trying to read it - you can use a simple .Contains check :
If ADEntry.Properties.Contains("givenName") Then
If that evaluates to false, you'll know there's no value to read, thus you can avoid the object reference error you're receiving.
Also, you may want to look into using a DirectorySearcher to preload the properties you're interested in, instead of pathing directly to a DirectoryEntry. I'm a C# guy, but this page was very helpful when I was developing my LDAP components :
Retrieving properties via DirectorySearch and SearchResult (C#) http://www.ianatkinson.net/computing/adcsharp.htm
I had the same issue.
I know this doesn't solve your question, but to get First Name and Last Name I had to use the following code:
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
string[] a = Context.User.Identity.Name.Split('\\');
System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
string FullName = ADEntry.Properties["FullName"].Value.ToString();
string FirstName = FullName.Substring(FullName.IndexOf(",") + 2);
string Lastname = FullName.Substring(0, FullName.IndexOf(","));
just in case it might be helpful to someone else
What I want to do is take the full contents of the address bar and see if everything after the site path (i.e. everything after the question mark), contains a certain string, and if it does then return a path using the site URL and that string.
An example and some code to make things understandable:
If I'm on www.example.com/?blah=image I want the code to look for the string image (after the question mark to prevent sites with image in the name to screw things up) and if it exists return www.example.com/images/ (with that current domain being looked up and not manually written as this will be used on mutliple sites)
Below is what I have written so far.
Public ReadOnly Property StorageRoot() As String
Get
Dim currentabsolute As String = System.Web.HttpContext.Current.Request.Url.AbsolutePath
Dim currentdomain As String = CurrentDomain
If currentabsolute.Contains("Media") Then
Return System.AppDomain.CurrentDomain.BaseDirectory & "\media\"
ElseIf currentabsolute.Contains("Docs") Then
Return System.AppDomain.CurrentDomain.BaseDirectory & "\docs\"
ElseIf currentabsolute.Contains("Image") Then
Return System.AppDomain.CurrentDomain.BaseDirectory & "\images\"
End If
End Get
End Property
I know CurrentDomain won't return anything and System.Web.HttpContext.Current.Request.Url.AbsolutePath doesn't seem to return what I am looking for so those are part of what I am hoping to get help with.
Any help will be appreciated and if you need any more clarification just ask.
Edit: Updated code
You're looking for the Request.QueryString member. To read the value of a specific query string parameter, try something along the lines of:
If Request.QueryString("Media") IsNot Nothing Then
Return currentdomain + "/media/"
ElseIf ...
If a query string does not contain the key in question, accessing that index will return nothing; otherwise it will return the value of that parameter. For instance, you could test to see if the string was constructed as ?Media=MyMedia with If Request.QueryString("Media") = "MyMedia".
If you want the raw query string itself, you could parse the Request.RawUrl member for everything after the question mark with something like:
Dim queryString As String = Request.RawUrl.SubString(Request.RawUrl.IndexOf("?"c) + 1)
Try this and let me know how it does for you:
Imports System.Web
...
Public ReadOnly Property StorageRoot() As String
Get
Dim requestUrl As Uri = HttpContext.Current.Request.Url
Dim newUrl As New UriBuilder(requestUrl.Scheme, requestUrl.Host, requestUrl.Port, HttpContext.Current.Request.ApplicationPath)
Dim currentQuery As String = requestUrl.Query
If String.IsNullOrEmpty(currentQuery)
' What to do if there is no query string?
Else If currentQuery.Contains("Media", StringComparer.InvariantCultureIgnoreCase) Then
newUrl.Path = newUrl.Path + "/media/"
ElseIf currentQuery.Contains("Docs", StringComparer.InvariantCultureIgnoreCase) Then
newUrl.Path = newUrl.Path + "/docs/"
ElseIf currentQuery.Contains("Image", StringComparer.InvariantCultureIgnoreCase) Then
newUrl.Path = newUrl.Path + "/images/"
End If
Return newUrl.ToString()
End Get
End Property