3

I am trying to open an Excel file (.xlsx) within a WPF .NET Core 3.1 app. Using Winforms, I am able to do

process.start("Resources/test.xlsx")

and the file will open.

In the WPF application doing the same thing results in an error

The specified executable is not a valid application for this OS platform

I am using the same code and opening the same file using both apps. Only the Winforms app will work, WPF will throw that error.

Is there a new way of opening files is handled using System.Diagnostics.Process.Start in .Net 3?

2 Answers 2

8

Looking around further, it seems that in .Net Core the UseShellExecute value is defaulted to false. Manually setting it to true fixed the issue. Here is the blog article I used to discover this fix: https://jeremybytes.blogspot.com/2019/08/converting-net-framework-to-net-core.html

Sign up to request clarification or add additional context in comments.

Comments

8

Something likes this

private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
{
    // Old way (.NET Framework 4.8)
    // string path = "Resources/test.xlsx";
    // Process.Start(path);

    // New way (.NET 6)
    ProcessStartInfo psInfo = new ProcessStartInfo
    {
        FileName = "Resources/test.xlsx",
        UseShellExecute = true
    };
    Process.Start(psInfo);
}

1 Comment

Thanks for putting in the code for the question (forgot I just put in a link which is bad...). +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.