Home > front end >  Using an exe file for IExpress
Using an exe file for IExpress

Time:11-03

I'm making an installer using IExpress to unpack the files, create a folder and move the files to the folder.

However, when choosing which program to run upon installation I can only get it to work using a batch-file:

@ECHO OFF

MD C:\PlugInFolder


MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\*.png" C:\PlugInFolder
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn.dll" C:\PlugInFolder

MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn2021.addin" C:\ProgramData\Autodesk\Revit\Addins\2021
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn2022.addin" C:\ProgramData\Autodesk\Revit\Addins\2022

Is it possible to run an exe file instead? I've tried the following C#-code (for one of the files only) but it only creates the folder and doesn't move the files:

// Creating paths
string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string folderName = "PlugInFolder";
string pathString = Path.Combine(path, folderName)   "\\PlugIn.dll";

string tempName = Path.GetTempPath()   "IXP000.TMP\\";

string fileName = "PlugIn.dll";
string filePath = tempName   fileName;

// Creating new directory
Directory.CreateDirectory(pathString);

// Moving files from temp folder
File.Move(filePath, pathString);

CodePudding user response:

There are a few typos in your code. Here's what could work, correctly using Path.Combine which is a powerful command:

// Creating paths
string source = Path.Combine(Path.GetTempPath(), "IXP000.TMP");

string dest1 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string dest2 = "PlugInFolder";
string dest = Path.Combine(dest1, dest2);

// Creating new directory
// Directory.CreateDirectory(dest);
// Don't create the directory, because we will use Directory.Move
// and it would raise an exception "Directory already exists" 

// Moving files from temp folder to destination
// File.Move is meant to move one file at a time.
// For an entire directory, use Directory.Move which can also be used for renaming the directory.
Directory.Move(source, dest);

And, by the way, is it a choice to put an application in the user profile dir? Otherwise, you may use:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

which would be C:\Users\yourName\AppData\Roaming for example in Windows 11.

  • Related