1 Attachment(s)
[2.0] Running with Relative paths
I've been using Relative paths for an extremely simple executable which copies files to a version of an external program.
C# Code:
File.Copy(@"RFI\Version 1.3\RFI Changer.exe", @"C:\*********\applications\***\RFI Changer.exe", True);
(The ****'s are related to the company I work for, so I'm not putting them on a public forum) :D
This works perfectly fine when I run the executable from windows, or debug it from Visual C#.
However, on occasion I need to run it from a different file. When I use the following code to run the executable...
C# Code:
Process UpdateProcess = new Process();
UpdateProcess.StartInfo.FileName = @"C:\Folder\Executable.exe";
UpdateProcess.Start();
... I get the attached error.
The original 'copy file' executable throws the attached error. Does anyone know why, or how I can fix it?
Here's the full contents of the Details box:
Quote:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.DirectoryNotFoundException: Could not find a part of the path 'RFI\Version 1.3\RFI Changer.exe'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at BDS_Setup.Form1.Form1_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
BDS Setup
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/BDS%20Macros/BDS%20Setup.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
Tekla.Structures.Model
Assembly Version: 1.0.6.0
Win32 Version: 1.0.6.0
CodeBase: file:///C:/WINDOWS/assembly/GAC/Tekla.Structures.Model/1.0.6.0__2f04dbe497b71114/Tekla.Structures.Model.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Thanks,
Qu.
Re: [2.0] Running with Relative paths
This happens to me a bunch of times. Some computers for some reason don't like using "directory\\somefile.txt" and need an absolute path.
Try doing this
Path.GetDirectoryName(Application.ExecutablePath) + "\\" + Path
Also make sure you are setting to working directory to where the exe is that you are executing.
UpdateProcess.StartInfo.WorkingDirectory = @"C:\Folder\";
Re: [2.0] Running with Relative paths
Quote:
Originally Posted by high6
This happens to me a bunch of times. Some computers for some reason don't like using "directory\\somefile.txt" and need an absolute path.
Try doing this
Path.GetDirectoryName(Application.ExecutablePath) + "\\" + Path
Also make sure you are setting to working directory to where the exe is that you are executing.
UpdateProcess.StartInfo.WorkingDirectory = @"C:\Folder\";
That would be StartupPath rather than ExecutablePath, which includes the EXE name.
Re: [2.0] Running with Relative paths
Thanks guys! I'll try that, see if it works...
Re: [2.0] Running with Relative paths
Quote:
Originally Posted by jmcilhinney
That would be StartupPath rather than ExecutablePath, which includes the EXE name.
Thats why I used Path.GetDirectoryName. Forgot about StartupPath.
Re: [2.0] Running with Relative paths
Quote:
Originally Posted by high6
Thats why I used Path.GetDirectoryName. Forgot about StartupPath.
Hehe... I didn;t even notice how you were using it, just that you were.