Error when reading AppManifest.xaml file in silverlight 4 - silverlight-4.0

I am new to silverlight. In my application I have to load different XAP files dynamically.
I am getting the below error when reading AppManifest.xaml file .
The method or operation is not implemented.
Here is my code.
Private Sub Button_Click_2(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim wc As New WebClient()
AddHandler wc.OpenReadCompleted, AddressOf EndOpenReadCompleted2
wc.OpenReadAsync(New Uri("WebPortalUI.xap", UriKind.Relative))
End Sub
Private Sub EndOpenReadCompleted2(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
Dim appManifest As String = New StreamReader(Application.GetResourceStream(New StreamResourceInfo(e.Result, Nothing), New Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd()
'Dim deploy As Deployment = TryCast(XamlReader.Load(appManifest), Deployment)
Dim deploy As XElement = XDocument.Parse(appManifest).Root //Here Error is coming
Dim asm As System.Reflection.Assembly = Nothing
For Each asmpart As AssemblyPart In deploy.Parts
Dim source As String = asmpart.Source
Dim streamInfo As StreamResourceInfo = Application.GetResourceStream(New StreamResourceInfo(e.Result, "application/binary"), New Uri(source, UriKind.Relative))
asm = asmpart.Load(streamInfo.Stream)
Next
Dim type As Type = asm.GetType("WebPortalUI.Reports") // Reports.xaml is one page
How can I solve this problem?
Regards,
JN

Related

Download PDF using WebView2 cookie

I'm trying to download a PDF using WebView2.
I can login on the browser but then i would like to download a PDF using WebClient.
But this returns me to the login screen.
Both WebView browsers use the same UserDataFolder.
I would like to download the PDF using the cookie settings used in the WebView2 browser.
Below is a sample that i'm using, but i don't know how to use it.
I believe i'm on the right track...
Private Sub WV_CoreWebView2Ready1(sender As Object, e As EventArgs) Handles WebView_Browser1.CoreWebView2InitializationCompleted
WebView_Browser1.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All)
AddHandler WebView_Browser1.CoreWebView2.WebResourceRequested, AddressOf CoreWebView2_WebResourceRequested
End Sub
Private Sub CoreWebView2_WebResourceRequested(ByVal sender As Object, ByVal e As CoreWebView2WebResourceRequestedEventArgs)
e.Request.Headers.SetHeader("Cookie", XXXXX) <<< i don't know how to use this
Dim addedDate = e.Request.Headers.GetHeader("Cookie")
End Sub
Private Async Sub WebView_Browser2_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles WebView_Browser2.NavigationCompleted
Dim url As String = pathtourl
Dim fileName As String = "pdf.pdf"
Dim webClient As WebClient = New WebClient()
webClient.Headers.Add(HttpRequestHeader.Cookie, WebView_Browser2.Cookie) <<< use cookie here to login?
webClient.DownloadFileAsync(New Uri(url, UriKind.Absolute), fileName)
End Sub
It would be great i somebody can help me with this!
Thanks!
Update
Dim LoginCookie As String
Private Sub WV_CoreWebView2Ready1(sender As Object, e As EventArgs) Handles WebView_Browser1.CoreWebView2InitializationCompleted
WebView_Browser1.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All)
AddHandler WebView_Browser1.CoreWebView2.WebResourceRequested, AddressOf CoreWebView2_WebResourceRequested
AddHandler WebView_Browser1.CoreWebView2.WebResourceResponseReceived, AddressOf CoreWebView2_WebResourceResponseReceived
End Sub
Private Sub CoreWebView2_WebResourceResponseReceived(ByVal sender As Object, ByVal e As CoreWebView2WebResourceResponseReceivedEventArgs)
LoginCookie = e.Request.Headers.GetHeader("Login")
End Sub
Private Async Sub WebView_Browser2_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles WebView_Browser2.NavigationCompleted
Dim url As String = pathtourl
Dim fileName As String = "pdf.pdf"
Dim webClient As WebClient = New WebClient()
webClient.Headers.Add(HttpRequestHeader.Cookie, LoginCookie)
webClient.DownloadFileAsync(New Uri(url, UriKind.Absolute), fileName)
End Sub
The Webclient accepts the cookie to be webClient.Headers.Add(HttpRequestHeader.Cookie, "CITY=NY") like this.
But the e.Request.Headers.GetHeader("Login") doesn't get me the cookie.
Again thank you for looking!
You can use this to get the cookies in C# similar pattern for VB.NET
List<CoreWebView2Cookie> cookieList = await WebBrowser.CoreWebView2.CookieManager.GetCookiesAsync(CurrentAddress);
Then loop through to get the string values you are looking for
for (int i = 0; i < cookieList.Count; ++i)
{
CoreWebView2Cookie cookie = TopicWebBrowser.CoreWebView2.CookieManager.CreateCookieWithSystemNetCookie(cookieList[i].ToSystemNetCookie());
cookieResult.Append($"\n{cookie.Name} {cookie.Value} {(cookie.IsSession ? "[session cookie]" : cookie.Expires.ToString("G"))}");
}

Visual basic Windows forms BitArray convert to string

Hi I made a code and it outputs random characters and unknown symbols.
The code is:
Function ReceiveMessages() As String
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
from = RemoteIpEndPoint.Address.ToString
Dim BitDet As BitArray
BitDet = New BitArray(receiveBytes)
Dim strReturnData As String = _
System.Text.Encoding.Unicode.GetString(receiveBytes)
rt = strReturnData
I don't think it is a problem with the receiving but it might.
This function is called by:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Try
receivingUdpClient = New System.Net.Sockets.UdpClient(11211)
Catch ex As Exception
End Try
ThreadReceive = _
New System.Threading.Thread(AddressOf ReceiveMessages)
ThreadReceive.Start()
End Sub
If you could help I would appreciate it.

How to wait for get request without freezing client

I have a simple button which sends a get request to retrieve a txt file on my website. Problem is it freezes the application while retrieving the info. How can I make it so the application doesn't freeze while waiting for the result?
Private Sub cmd_ClickMe_Click(sender As Object, e As EventArgs) Handles cmd_ClickMe.Click
Dim request As String = String.Format("http://www.*****/database/test.txt")
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString(request)
MessageBox.Show(result)
End Sub
I've also tried the following but it doesn't work (says "webClient.DownloadStringAsync(myUri)" does not produce a value:
Private Sub cmd_ClickMe_Click_1(sender As Object, e As EventArgs) Handles cmd_ClickMe.Click
Dim request As String = String.Format("http://www.****.com/database/test.txt")
Dim webClient As New System.Net.WebClient
Dim myUri As Uri = New Uri(request)
Dim result As String = webClient.DownloadStringAsync(myUri)
MessageBox.Show(result)
End Sub
Use DownloadStringAsync(Uri) instead of the DownloadString(uri).
The DownloadStringAsync method does not block the calling thread.
Here is an example how to use it:
Dim wc As New WebClient
' Specify that you get alerted
' when the download completes.
AddHandler wc.DownloadStringCompleted, AddressOf AlertStringDownloaded
Dim uri As New Uri("http:\\changeMe.com") 'Pass the URL to here. This is just an example
wc.DownloadStringAsync(uri)
End Sub
Public Shared Sub AlertStringDownloaded(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
' If the string request went as planned and wasn't cancelled:
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim myString As String = CStr(e.Result) 'Use e.Result to get the String
MessageBox.Show(myString)
End If
End Sub

How to download .exe file with progress bar - VB 2012

I am trying to create an updater for my program which automatically download's the latest version of my program from the web. Now I want this process to be done using a progress bar (so when the download progress is at 50% the progress bar is half-way through). This is my code:
Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
client.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim url As String = "MY DOWNLOAD LINK"
'Download
Dim client As WebClient = New WebClient
AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
client.DownloadFileAsync(New Uri(url), "C:\Users\User\Desktop\BACKUP\TESTING\New folder\1.exe")
End Sub
End Class
Now I know that the place where the file is saved has been inputed manually by me , but I will change that later. My problem currently is that the file is not being downloaded. However when I change the DownloadFileAsync method to DownloadFile , my program downloads the file. However with the DownloadFile method I will not be able to use the progress bar to track the download progress. Any help is much appreciated :-)
Don't know what you mean, when you say that the file isn't downloaded? You get an Error/Exception? Nothing happens at all? Did you place breakpoints, debug.prints etc?
With VS2012 and asyn/await you can put everything into one method an keep a "linear code-flow". Import System.Threading and System.Threading.Tasks
Private Async Function DownloadWithProgress(ByVal url As String, ByVal p As ProgressBar) As Task(Of Integer)
Dim wc As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf wc.GetResponse)
p.Value = 0
p.Maximum = CInt(resp.ContentLength)
Dim rqs = resp.GetResponseStream
Dim bufsize As Integer = 1 << 16
Dim buffer(bufsize) As Byte
Dim got As Integer = 0
Dim total As Integer = 0
Do
got = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufsize, Nothing)
total += got
Me.Label1.Text = "got: " & total.ToString
p.Increment(got)
Loop Until got = 0
Return total
End Function
In this sample, the data from the web is downloaded into an array, but you can of course also write it into a file, or do whatever you want with the data.
Sample for usage:
Private running As Boolean = False
Private Async Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If running Then
MessageBox.Show("Cant you see, I'm working?")
Exit Sub
Else
running = True
End If
Await DownloadWithProgress("http://download.thinkbroadband.com/5MB.zip", ProgressBar1)
running = False
End Sub

Opening listview items with a double click vb.net

I want to open items from a list view with a double click.
Imports System.IO
Imports System.Xml
Public Class cv7import
Private Sub cv7import_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim caminho As String
caminho = "C:\Documents and Settings\Software\Ambiente de trabalho\cv7import"
lstvicon.View = View.Details
lstvicon.GridLines = False
lstvicon.FullRowSelect = True
lstvicon.HideSelection = False
lstvicon.MultiSelect = True
lstvicon.Columns.Add("Nome")
lstvicon.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
Dim DI As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(caminho)
Dim files() As System.IO.FileInfo = DI.GetFiles
Dim file As System.IO.FileInfo
Dim li As ListViewItem
For Each file In files
li = lstvicon.Items.Add(file.Name)
Next
End Sub
Private Sub btnimp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimp.Click
Dim caminho As String
caminho = "C:\Documents and Settings\Software\Ambiente de trabalho\cv7import"
Dim items() As ListViewItem = lstvicon.SelectedItems.Cast(Of ListViewItem).ToArray
Dim csv() As String = Array.ConvertAll(items, Function(lvi) String.Join(",", lvi.SubItems.Cast(Of ListViewItem.ListViewSubItem).Select(Function(si) si.Text).ToArray))
IO.File.WriteAllLines("C:\Documents and Settings\Software\Ambiente de trabalho\cv7import\teste.csv", csv)
End Class
That's the important part of the code, I was think of using onclick but I cant seem to get anywhere with it, any suggestions?
I also considered using and Open File Dialog but I dont think it can be done without the user's input of a path
I'm assuming that when you say open, you mean you want to open the associated file in the default program for that file type. In that case, you need to be storing the full path to the file in the list view. That can be accomplished via this code:
For Each file In files
li = lstvicon.Items.Add(file.Name)
li.Tag = file.FullName
Next
You will then need to add an event for the listview's double-click method. Within that event you'll want to look at the selected item and run the default program for it.
Private Sub lstvicon_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstvicon.DoubleClick
Process.Start(lstvicon.SelectedItems(0).Tag)
End Sub