How to distribute my Vb.net Webview2 app? - vb.net

So I developed an vb.net app with webview2. My problem is: if I copy the entire debug folder to a new computer, It works. But if I create an installer with the entire debug folder, it does not work. Any idea?
I'm using the stable package from NuGet.
When I copied and pasted the files I didn't even need to bother with installing the evergreen release and it worked.

Are you using the default user data folder and are you installing to Program Files? If so, you may need to explicitly specify your user data folder to an app data folder for your application. Read more about Managing user data folders in the WebView2 documentation.
The default user data folder is the path of the host app executable with ".WebView2" appended to the end. So notepad's default would be "C:\windows\system32\notepad.exe.webview2". This doesn't work when the path containing the host executable doesn't have permissions to allow the host app to create the user data folder. Most installers run elevated and have additional permissions to create the application's installed files and folders. But when the installed app runs it generally doesn't have permission to modify the contents of its install path. Instead you should explicitly specify a user data folder and manage that folder including potentially deleting it when your app is uninstalled.

Public Sub New()
Dim url As String = Nothing
InitializeComponent()
InitializeBrowser(url)
End Sub
Private Async Sub InitializeBrowser(ByVal Optional url As String = Nothing)
Dim userDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\SoftwareName"
Dim env = Await CoreWebView2Environment.CreateAsync(Nothing, userDataFolder)
Await WebView21.EnsureCoreWebView2Async(env)
WebView21.Source = New Uri("https://www.google.com/")
End Sub

Maybe this can be your solution:
On March 14th, Microsoft began auto-installing the 'Microsoft Edge WebView2 Runtime' on Windows 10 machines without any notification to users.
Source: https://www.bleepingcomputer.com/news/microsoft/microsoft-is-auto-installing-the-windows-10-webview2-runtime/

Related

What's the best way to place a local SQLite database file in a WinForms application to publish the project on GitHub and distribute the executable?

I'm trying to push to GitHub a Windows Forms VB.Net application which does CRUD operations on a local SQLite database file, but I realized the db3 file and System.Data.SQLite.dll are excluded from the push because the contents of bin/Debug folder where they're located are a part of the .gitignore policy template on Visual Studio, which absolutely makes sense.
I have tested the .exe file out of this Debug development folder and couldn't run the application either, throwing the exception: "Could not load file or assembly 'System.Data.SQLite, Version=1.0.116.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies"
My Problem is all the guides I've checked to use a SQLite in a Windows Forms project place the database file in bin/Debug, I guess for the simplicity of the tutorial. So this way of referencing the SQLite db3 in bin/Debug works fine in my application:
Public dbFullPath As String = Application.StartupPath & "\\myDatabase.db3"
Public conStr As String = String.Format("Data Source = {0}; version = 3;", dbFullPath)
However, I don't know how to place the database at the same level of other project files like .vb Forms and the Resources folder and reference it so the app works and all the necessary files are pushed to my public repository.
I created an App_Data folder at project level and placed the database file inside and then tried to replace the path String from:
Public dbFullPath As String = Application.StartupPath & "\\myDatabase.db3"
to this:
Public dbFullPath As String = "App_Data\\myDatabase.db3"
But I'm unable to open the database in a different place other than bin/Debug.
Thank you very much for your help.
In order to run the application outside of the visual studio environment you will need to copy both the x64 and x86 folders which are generated at build time
In Chem4Word we use the NuGet package SQLite 1.0.117 to read and write to a SQLite database which is deployed to C:\ProgramData\Chem4Word, but it could be anywhere in the file system to suit your purpose.
Our installer also deploys the contents of the above folders (x64 and x86) beneath the application folder in C:\Program Files (x86)\Chem4Word as shown below
The "seed" database is stored as an embedded resource, hence gets checked in to the repository.

Use external exe in VB.NET project

I have a VB.NET program (I am working on this program).
I want to include an "external" exe file with my application while creating setup, and distribute it along with my software. I want to copy "this exe" to the installation directory on user demand (when user clicks a button) using my software. I know I can add "this" exe as a "Resource" file but how can I copy it to the installation directory from "Resources"? How to access "this" exe after I create installer?
I tried this:
System.IO.File.Copy(My.Resources.abc, "C:\Users\LabOne\Desktop\abc.exe")
but this didn't work. Please Help.
You need to write the byte-data of the resource to a local filepath.
Dim resource As Byte() = My.Resources.File
Using fs As New FileStream("C:\file.exe", FileMode.Create, FileAccess.ReadWrite)
fs.Write(resource, 0, resource.Length)
End Using

How to use created sub folder in public folder on Play Framework 2.2.x

I created "xlsfiles" subfolder in public folder, and I used it folder for create xls file by request.
And when user send request to server to get this xls file I serve this file to client.
When I run project on Dev Mode all working perfectly, but when I run project on Production Mode not exist "xlsfiles" subfolder and I get "FileNotFoundException" exception.
Have any solution? How to make create sub folder in the project and create file in it?
Use Files class from standard Play framework API:
http://www.playframework.com/documentation/2.2.x/api/scala/index.html#play.api.libs.Files$

vb.net file paths causing crashing in published exe

i am making a 'simple' program that on button click does this:
Private Sub Button4_Click(sender As Object, e As EventArgs)
Dim proc As New System.Diagnostics.Process()
proc = Process.Start("resources\navcoder.exe", "")
proc.WaitForExit()
End Sub
all works fine when testing in visual studio but not once i publish and install, even if the resource folder is in the install directory.
if i change it to:
proc = Process.Start("c:\resources\navcoder.exe", "")
it works fine, but i obviuosly needs to have the folder there with the required files in it.
what am i doing wrong?
A lot of people seem not to realise what resources are. The whole point of adding a resource to your project is to have the data it contains compiled into your EXE. The Resources folder in your project is just a place to store the original source files. It doesn't exist as far as the application is concerned, just as your VB source code files don't exist. When you build your project, the data in those resources is compiled into your EXE so they are no longer files and can no longer be used as files.
That's why you don't embed other EXE files as resources. You could extract the resource and save it as a file first but I would recommend against that. Add a new folder to your project and add the EXE file and any dependencies to that folder and set their Build Action to Content. They will then be copied to your output folder as is. You can then execute the EXE file because it is an EXE file. You should also use Application.StartupPath as the root of the file path rather then relying on the current directory being what you think it will be.
You should always check for existance, if its a web app, would do this in the application start in the global asax. If you are running this under a different user account, check the account has permissions. Otherwise even if the directory exists, it will fail if it cant access it or does not have permissions to execute the file.
Might be able to tell you more if you give the actual exception. I.e Unauthorized or does not exist.

How to save StorageFolder

I am creating a (sort-of) downloading manager for windows 8 as a metro app. I need to let the user pick his download directory.
So we can get a reference to a folder using the folder picker:
Windows.storate.Pickers.FolderPicker.pickSingleFolderAsync.then(function (folder)
{
//myFolder
folder
}
Now my question is how would I save this folder reference, so that I can still access it after the user closes the app?
There seems to be applicationData that we can use, but does that keep the folder permission in-tact?
I'm using HTML+JS, though since this is an API question it doesn't really matter.
The recommended way to keep track of the folder is to use the AccessCache APIs, which will keep track of the files and folders your app has been given permissions for from the pickers.
To store a folder in the cache:
var folder = //Get a folder from the picker
var storageItemAccessList = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList;
storageItemAccessList.Add(folder,"identifyingString");
And to get the same folder out of the cache later use GetFolderAsync with the identifying string that you used when you stored the folder.
Note that the folder will be kept in the cache even if it has been deleted on the disk. You will get a FileNotFound exception when you try and open it though.