Local html url in webbrowser control (visual basic) - vb.net

I'm a beginner in VB, I'm trying to display html page in the webbrowser control.
when I copy the full path of the html file, and put in the url properties of the webbrowser control, everything works. However, when I build the exe file and run it in different computer, the html page can not be displayed.
I know this has to do with the html file path, I'm trying to find a way to display html page using webbrowser control in any computer.
any help will be great guys.

Try:
WebBrowser1.Navigate(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "\info.html")
remember to add
Imports System.IO

This is a little late, but better late then never! Sorry I did not find this sooner!
Anyway, instead of adding the file url in the URL property of WebBrowser1, here is what you need to do:
In Form1_Load add the following code:
Dim appPath As String
appPath = Application.StartupPath
WebBrowser1.Navigate(appPath & "/html-file-name-here.html")
Change the "html-file-name-here.html" to what your HTML file name is.
Then when you compile your app, just put your html file in the folder where the app is launching from .

Related

How do I upload a file without showing Openfiledialog on webbrowser vb.net?

help with webbrowser!
How do I upload a file without showing Openfiledialog?
I made an example in imacros(Firefox) and I throw this code
TAG POS=1 TYPE=INPUT:FILE ATTR=* CONTENT=C:\Users\MyUser\Desktop\MP3\audios\IdiomaC_9179192217_20150703-000023-all.mp3
How can I send this instruction from vb.net?
It's very important, thank you very much
i cant use imacros api for .net because it to work I have to use an own browser of imacros, and for other functions that I use to not work in the imacros browser, only in the own of vs (WebBrowser)

VB.Net Run.exe with Form button

I'm pretty new to VB so I need a bit of help with some coding.
I made a program that should download a certain file to what ever directory the user wants, but now i want my program to run that certain file but i don't know how to do it since the user used his/her own directory.
Like i want the program to run that certain file no matter where its saved, how do i do that?
I do know this code:
System.Diagnostics.Process.Start("C:\")
but this doesnt really work since i have to put in a directory before i use the program.
You can get the path of the SFD by using filename.
Dim Path as String
Path = SaveFileDialog.FileName
Then run the file.
System.Diagnostics.Process.Start(Path)
Found another way of doing it,
I just used:
file.open(textbox1.text)
And made it take the text forom the the other textbox the user browsed the file to

How do I download a TXT and then read it?

Okay so I have a program that is supposed to download a TXT file which ONLY contains a URL from my Dropbox, save it on my desktop, and then open the webbrowser like Process.Start(DownloadedFile).
My code looks like this:
Dim path As String = "C:\Users\" & SystemInformation.UserName & "\Desktop"
My.Computer.Network.DownloadFile("https://www.dropbox.com/s/uy9jpt1em3o6khp/download_location.txt?dl=1", path + "\" + "Download_Location" + ".txt")
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(path + "\Download_Location.txt")
Process.Start(fileReader)
Now my problem is that, the program DOES download my txt file and name it correctly. But even if I know that there is text in the text file, when the program downloads it and saves it on my Desktop named "Download_Location.txt", it is empty. The downloaded file doesn't conatin any text even if Im 100% sure that there should be a URL text.
And when my program reached the code where Process.Start(fileReader) it gives me an error:
You can not start the process because no file name is specified.
Thanks a lot! And sorry for my bad english.
When downloading files via a URL you are required to use a direct URL, due to that you download exactly the URL you specify. The reason you can download it from your web browser is because it first loads the page from the first link, then the page tells the browser to redirect to the actual file.
Direct links through DropBox are accessed via the dl.dropboxusercontent.com website, which is what you'll need to get the direct link to your file. The reason DropBox uses this system is probably because dropbox.com/s/... is yet a bit shorter than dl.dropboxusercontent.com/content_link/...
Having this said, switching your download URL from what you have now to: https://dl.dropboxusercontent.com/content_link/Uxdm1CQxQ50LBm5QejnkGLOIXJf8QL2I‌​ui95XjhMUL2Wz4gjzBwiHttuA07RkbOl/file?dl=1 should work.

Illegal character in path (of Resources file)

I have a Windows Control Library project (visual studio 2010). I put in the compile tab for it to be a com element (I use it as an addin for another program).
My question is the following:
I have a .cvs file in my resources that I use to parse some main settings.
The line of code that reads this file gives an error when I run the addin.
code line:
dim reader as new streamReader(My.Resources.standards)
(the file is called standards)
error I get when running the com element:
Illegal character in path.
The program runs nicely when I test it as a normal windows form project.
Anyone know how to fix this? Or how to do decent debugging when testing com elements.
Thanks.
This does not have anything to do with COM, scratch that as a cause of your problem. Clearly your My.Resources.standards property returns a string, not a stream. Which is pretty normal when you add a text file as a resource. It makes StreamReader try to open a file on disk using the content of the .cvs resource as the path of the file. That will of course not work well.
You could use a StringReader instead. Or just use the returned string as-is.
Change it to following
dim reader = new string(My.Resources.standards)
you have a string now that can be used in regex
Cobus

How do I publish a folder along with my VB.NET program that contains.html?

I have a VB.NET program that I wish to to publish. In the code it references a HTML page that I created. Instead of having the URL hard coded (example: www.test2.com/folder/index.html)
I would like to have it relative to wherever the encoder is installed to (example: /folder/index.html)
How can I do this?
Thanks!
In VB.Net you have either
Dim lPath As String = Application.ExecutablePath
Which gives you the full path and app.name (which you can remove) or
Dim lPath As String = Application.StartupPath
Which gives you the directory the application started up in ..
Not sure I know the answer to the clickonce question, as we use our own deployment method at work but if you :-
Add your file via Project Explorer
Right click on file, select properties and set Build Action to "content"
Go to Project, yourprojectnameProperties, then Publish tab, then
Application Files button
you should see the file listed there then set to Include(auto).
.... or copy and paste them using internet explorer into the project explorer
If the file is referenced within your solution, the publish operation should automatically include the file to be published.
as for reference, if the html is hosted with in same website, then you can use a relative path from the page you are linking to.
You can also reference the file in your code by using Server.MapPath("relativepathtofile") and the relative path to the file you're referencing.