10-15-2019 05:26 AM
Hi,
I tried to use the Microsoft.WindowsAPICodePack.Shell dll as shown in the attachment. I don't have any clue what I've might done wrong. I already tried to run LV as administrator but that didn't help.
Running the exact same code in C# is working.
Thanks in advance and best regards,
Lisa
Solved! Go to Solution.
10-16-2019 04:12 AM - edited 10-16-2019 04:16 AM
C# probably does things under the hood, like maybe initializing forms\presentationframework.
You could try to compile an .NET assembly with the C# code to see if that works. .NET has a build in C# compiler, so you won't need Visual Studio...
Why do you want this? LV has a multi file selection dialog.
Also, Microsoft.WindowsAPICodePack is probably just a wrapper. It's not shipped with WIndows anymore. The function probably calls Microsoft.Forms.OpenFileDialog or Microsoft.Win32.OpenFileDialog (OTOMH). Both of these (I didn't bother downloading WindowsAPICodePack ) just hang infinitely in LV, without ever showing a dialog.
10-16-2019 07:33 AM
Hi,
I did try it in Visual Studio and it worked. When using a dll as a wrapper the same error occurs - hence your assumption might be correct.
I need it because I don't want to open files but I need multiple folder directories. Do you have any other ideas how to realize that in LV?
Thank you!
10-17-2019 12:33 AM
I found a solution. Just built an exe... Was probably the easiest way to implement multiple folder selection 🙂
10-17-2019 02:49 AM
You'd be helping others a lot if you could post some code. It's probably trivial, but most of us are good in LV, not C#.
10-17-2019 09:19 AM
of course:
using System;
using Microsoft.WindowsAPICodePack.Dialogs;
namespace MF
{
class Program
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0 && System.IO.Directory.Exists(args[0]))
{
var openFolder = new CommonOpenFileDialog();
openFolder.AllowNonFileSystemItems = true;
openFolder.Multiselect = true;
openFolder.IsFolderPicker = true;
openFolder.Title = "Select folders";
openFolder.InitialDirectory = args[0];
if (openFolder.ShowDialog() == CommonFileDialogResult.Ok)
{
Console.WriteLine(string.Join(";", openFolder.FileNames));
}
}
}
}
}
couldn't be easier I guess 🙂
10-18-2019 03:08 AM - edited 10-18-2019 03:14 AM
@lisastl wrote:
couldn't be easier I guess 🙂
Here's a VI that compiles the exe.
It's convenient, there's no need to install VS or anything. And the entire compilation fits in SCC.
I can't actually compile the exe, as I didn't install WindowsAPICodePack. But I modified a VI that creates a dll (set generateExecutable to false, change the extension and the code of course), so it should mostly work.
10-18-2019 03:43 AM - edited 10-18-2019 03:44 AM
Thank you for your answer!
I don't get why you would need that... (No offense - just really don't understand it.) Isn't it easier to just call the exe in the System Exec VI? Or does that mean that the LV runtime engine was used?
You can find my solution in the attachment. You'll need to adapt the path in the VI to the direction where you put the exe. And you'll need to put both dlls at this place. But then you won't need to install the APICode pkg. But unfortunately you'll need the runtime engine for VS 2017 x64.
10-18-2019 04:58 AM
@lisastl wrote:
Thank you for your answer!
I don't get why you would need that... (No offense - just really don't understand it.) Isn't it easier to just call the exe in the System Exec VI? Or does that mean that the LV runtime engine was used?
You'd use that code to compile the C# executable.
That way, you don't need to download and install VS, saving gigabytes of HD space. Also, the VI ends up in source code control, so the next guy\girl doesn't need to install VS...
Once you have the .NET exe, you call it just like before.