Saving a downloaded file into resources VB.NET - vb.net

Is it possible to download a file using webclient and save it into my application resources? something Like,
Dim w As WebClient = New WebClient
w.DownloadFile("url", *to my resources* )

Understood. it is not possible (if any one looking for this)

Related

Download dynamically generated content in VB.net

I am trying to download a dynamically generated CSV file over HTTP in VB.net. I have tried various download methods, but all generate the following error:
System.Net.WebException was unhandled. The request was aborted: The connection was closed unexpectedly.
The specific CSV file I am trying to fetch is http://www.ukrepeater.net/csvcreate.php
I can only assume the error is due to the fact that the data isn't located at the actual URL referenced, but is just a dynamically generated file that, in a regular browser, just pops-up a download window.
I truly have tried to find every similar question already asked, but I cannot find a solution anywhere. Any code suggestions or links to the answer would be gratefully received!
Try with System.Net.WebClient class. You can save the content of your csv file in a string variable:
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://www.ukrepeater.net/csvcreate.php")
or you can download the file to your file system:
Dim webClient As New System.Net.WebClient
webClient.DownloadFile("http://www.ukrepeater.net/csvcreate.php", "c:\file.csv")
More info about System.Net.WebClient can be found on this MSDN page

Download zip file from web page where the file name is not known

I've been looking into downloading files from a web page. Referencing MSDN
However, the catch is, I do not know the name of the file I will be downloading.
I'm creating a VB application that runs on a schedule which will check the version of the file we have on our system with the one on the website. I've gotten this working.
The naming conventions of the file is [Description].[Version].[Zip]:
ACCESSDB.2.1.3.zip
The issue is whether the publisher of this website follows a convention of 2.1.3 to 2.1.4
It doesn't seem very robust for me to increment our version and download that.
I would like to download using a wildcard if possible, can this be achieved?
Try
Dim myStringWebResource As String = Nothing
Dim myWebClient As New WebClient()
'myStringWebResource = remoteUri + fileName
myWebClient.DownloadFile("http://website.co.uk/ACCESSMDB[Wildcard].zip", "W:\Newest.zip")
Catch ex As Exception
MsgBox(ex)
End Try

Reading Xml from an absolute path

I need to access a remote Xml document from a WCF service. Right now I have:
XmlReader reader = XmlReader.Create("path");
But since the Xml doc is elsewhere on our network I need to give the XmlReader an absolute path, as opposed to having it look deeper in the project folder. How do I do this? I've found surprisingly little information about this. It seems like this should be a simple thing to do. Any help is appreciated!
Thanks
You can use overload that accepts Stream parameters as follows:
using (FileStream fileStream = new FileStream(#"\\computername\shared path"))
using (XmlReader reader = XmlReader.Create(fileStream))
{
// perform your custom code with XmlReader
}
Please note that you need appropriate permission to open remote stream. In WCF service context you may need to use impersonation.

Access .exe file in resources?

I have an encrypted program in my resources in a project I'm working on and I need to access that file like this.
Dim fs As New FileStream(filepath, FileMode.Open)
Any help?
try GetManifestResourceStream - it gives you a stream to read the resource by name. This stream can be used for example to decrypt and/or write to a real file and/or load as an Assembly (if the embedded resource is a .NET exe/DLL)...
For sample code see http://www.eggheadcafe.com/microsoft/VB-NET/33899321/how-to-extract-a-resource-to-a-file.aspx .

Uploading multiple files with VB.Net

I need to upload multiple files in a winforms application. So far I've been using a webclient and while this is working fine I'm wondering if there is a better way for doing this. Does the webclient make a new connection for every request or does the connection persists between uploads?
Dim Ftpclient As New System.Net.WebClient()
Ftpclient.Credentials = New System.Net.NetworkCredential(username, password)
Dim Files As New Dictionary(Of String, String)
''//Fill dictionary with items for upload here
For Each RemoteFile As String In Files.Keys
Ftpclient.UploadFile(RemoteFile, Files(RemoteFile))
Next
It'll create a new TCP connection for every file, because it's way HTTP works.
IMHO, not a bad thing in your scenario.
It depends on what protocl you are using for upload. If you are using HTTP, then the client will reuse the previous connection if it can. I am not sure about FTP - I think FTP also supports keep-alive.
In any case, if you are concerned about performance, you should use Wireshark to see how the connection usage is being accomplished. Is it creating a new connection everytime?