Answered my own question with the below
FileCopy("C:\Program Files\Imparja Television\Programs\HR-Nine.xspf", Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\HR-Nine.xspf")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi guys,
I am attempting to write a line or 2 to perform a simple copyfile command in Visual Studio.
My idea is to have the files moved from the "C:program files" to the user's desktop no matter what user is logged into the machine at the time.
I have been able to use the copydirectory command but I can't seem to get it to work with single files.
I want the files to be moved to the desktop and not in a folder on the desktop either.
My Code
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
'Move Streaming files to desktop
Dim strDestFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim dirinfo As IO.DirectoryInfo
My.Computer.FileSystem.CopyFile("C:\Program Files\Imparja Television\Programs\HR-GEM.xspf", strDestFolder \ "HR-GEM.xspf")
End Sub
The error I get
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidCastException: Conversion from string "C:\Users\michael.smith\Desktop" to type 'Long' is not valid.
---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDecimal(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value)
at System_Setup.Form2.Button16_Click(Object sender, EventArgs e) in D:\Scripts\VBS\Setup VS 2022\System Setup\System Setup\Form2.vb:line 96
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
System.Private.CoreLib
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Private.CoreLib.dll
----------------------------------------
System Setup
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Scripts/VBS/Setup%20VS%202022/System%20Setup/System%20Setup/bin/Debug/net6.0-windows/System%20Setup.dll
----------------------------------------
Microsoft.VisualBasic.Forms
Assembly Version: 6.0.2.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/Microsoft.VisualBasic.Forms.dll
----------------------------------------
System.Runtime
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Runtime.dll
----------------------------------------
System.Windows.Forms.Primitives
Assembly Version: 6.0.2.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/System.Windows.Forms.Primitives.dll
----------------------------------------
Microsoft.Extensions.DotNetDeltaApplier
Assembly Version: 17.0.0.0
Win32 Version: 17.4.326.54890
CodeBase: file:///c:/program%20files/microsoft%20visual%20studio/2022/community/common7/ide/commonextensions/microsoft/hotreload/Microsoft.Extensions.DotNetDeltaApplier.dll
----------------------------------------
System.IO.Pipes
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.IO.Pipes.dll
----------------------------------------
System.Linq
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Linq.dll
----------------------------------------
System.Collections
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Collections.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 6.0.2.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/System.Windows.Forms.dll
----------------------------------------
System.Diagnostics.TraceSource
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Diagnostics.TraceSource.dll
----------------------------------------
System.Collections.Concurrent
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Collections.Concurrent.dll
----------------------------------------
System.ComponentModel.Primitives
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.ComponentModel.Primitives.dll
----------------------------------------
System.Runtime.InteropServices
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Runtime.InteropServices.dll
----------------------------------------
System.Drawing.Primitives
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Drawing.Primitives.dll
----------------------------------------
System.Console
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Console.dll
----------------------------------------
System.Threading
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Threading.dll
----------------------------------------
System.Threading.Overlapped
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Threading.Overlapped.dll
----------------------------------------
System.Security.AccessControl
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Security.AccessControl.dll
----------------------------------------
System.Collections.Specialized
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Collections.Specialized.dll
----------------------------------------
System.Security.Principal.Windows
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Security.Principal.Windows.dll
----------------------------------------
System.Security.Claims
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Security.Claims.dll
----------------------------------------
Microsoft.Win32.Primitives
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/Microsoft.Win32.Primitives.dll
----------------------------------------
System.Threading.Thread
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Threading.Thread.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Runtime.Loader
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Runtime.Loader.dll
----------------------------------------
System.ComponentModel
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.ComponentModel.dll
----------------------------------------
System.Drawing.Common
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/System.Drawing.Common.dll
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/Accessibility.dll
----------------------------------------
System.ComponentModel.TypeConverter
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.ComponentModel.TypeConverter.dll
----------------------------------------
Microsoft.VisualBasic.Core
Assembly Version: 11.0.0.0
Win32 Version: 11.100.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/Microsoft.VisualBasic.Core.dll
----------------------------------------
System.Numerics.Vectors
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Numerics.Vectors.dll
----------------------------------------
System.Memory
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Memory.dll
----------------------------------------
Microsoft.Win32.SystemEvents
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.11/Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Collections.NonGeneric
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Collections.NonGeneric.dll
----------------------------------------
System.ObjectModel
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.ObjectModel.dll
----------------------------------------
System.Private.Uri
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Private.Uri.dll
----------------------------------------
System.Runtime.CompilerServices.Unsafe
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Runtime.CompilerServices.Unsafe.dll
----------------------------------------
System.Diagnostics.StackTrace
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Diagnostics.StackTrace.dll
----------------------------------------
System.Reflection.Metadata
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Reflection.Metadata.dll
----------------------------------------
System.Collections.Immutable
Assembly Version: 6.0.0.0
Win32 Version: 6.0.1122.52304
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.11/System.Collections.Immutable.dll
----------------------------------------
************** JIT Debugging **************
Answered my own question with the below
FileCopy("C:\Program Files\Imparja Television\Programs\HR-Nine.xspf", Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\HR-Nine.xspf")
Use the methods in System.IO.Path,
'Move Streaming files to desktop
Dim srcFile As String = "C:\Program Files\Imparja Television\Programs\HR-GEM.xspf"
Dim destFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim destFile As String = IO.Path.Combine(destFolder, IO.Path.GetFileName(srcFile))
My.Computer.FileSystem.CopyFile(srcFile, destFile, overwrite:=True)