0

I'm new to using C# and WPF so I apologize if my terminology is incorrect.

I want trying to make a program to automate small businesses workflows, the base application is the same for everyone, but how their order data is structured is going to be different.

So, my goal would be to build them a custom file that contains function on how to parse their order data, then have the user drag and drop that file into the application to which the application would use it.

I have a way for them to select the file and move it into the applications directory here:

private void SelectFile_Click(object sender, RoutedEventArgs e)
{
    // Create OpenFileDialog 
    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

    // Set filter for file extension and default file extension 
    dlg.DefaultExt = ".cs";
    dlg.Filter = "C# Files (*.cs)|*.cs";

    // Display OpenFileDialog by calling ShowDialog method 
    Nullable<bool> result = dlg.ShowDialog();

    // Get the selected file name and display in a TextBox 
    if (result == true)
    {
        // Open document
        string filePath = dlg.FileName;
        string relPath = AppDomain.CurrentDomain.BaseDirectory;
        string destPath = System.IO.Path.Combine(relPath, dlg.SafeFileName);
        Trace.WriteLine(destPath);
        File.Move(filePath, destPath, true);
        
    }
}

But now I run into an issue when I want to call from that file I get a error "CS0103" the file doesn't exist in the current context. So I am now unable to run the application Is there a way around this error? so it will only run when the file exists and get rid of this error?

I have tried to check if the file exists before calling it, but the same error prevents me from running my app.

//call your order parser script
if (File.Exists("OrderParser.cs"))
{
    OrderParser.OrderParser.Parser(item);
}
burnsi
  • 6,194
  • 13
  • 17
  • 27
akt1000
  • 1
  • 1
  • Debug the code and make sure you path and filename are correct. – jdweng Jan 28 '23 at 18:45
  • 1
    Why are you changing the file's directory from where the user specified? – Louis Ingenthron Jan 28 '23 at 18:50
  • 1
    So you're planning to provide the users custom .CS files encapsulating new functionality and have these be compiled and executed at runtime? You might be taking on a much bigger task here than you realize. You might be better off using SQL files containing custom queries for your app to run for them. Otherwise you're looking at a full blown plugin system, and that is, well, a project. – Emperor Eto Jan 28 '23 at 18:54
  • 1
    As well as the other (excellent) comments here, you might want to rethink moving the file into the app's folder, as that will require elevated permissions (assuming it's installed in `C:\Program Files` or the like. – Avrohom Yisroel Jan 28 '23 at 20:57
  • Dynamics CRM already ate your lunch. https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/configure-workflow-steps?view=op-9-1 – Andy Jan 28 '23 at 23:18
  • There are numerous no code workflow solutions. Microsoft workflow is now deprecated but if you can live with .net 4.5 offers drag drop designer support. https://learn.microsoft.com/en-us/dotnet/framework/windows-workflow-foundation/ – Andy Jan 28 '23 at 23:24
  • If your functions are kind of structured you can use mef. Build a number of dll and the user's pick whichever implementation they prefer. https://learn.microsoft.com/en-us/dotnet/framework/mef/ – Andy Jan 28 '23 at 23:27

0 Answers0