.net - Visual Studio 2013 - 将文件移动到另一个路径

标签 .net vb.net file-move

大家下午好,

我正在尝试创建此代码,该代码允许我根据在 TextBox1.Text 中输入的内容在目录中创建一个新文件夹,然后打开一个对话框并选择一个 PDF,然后将文件路径放入 TextBox2 (这同样适用于 TextBox3 中的单独 PDF)。

An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.VisualBasic.dll

Additional information: Could not complete operation since a directory already exists in this path '\\ANVILSRV\Public\Completed Works Orders\98789'.       

-

这是我在尝试完成操作时遇到的错误,它创建文件夹但不移动任何文件。

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

    Dim txt As String
    txt = TextBox1.Text

    If My.Computer.FileSystem.DirectoryExists("\\ANVILSRV\Public\Completed Works Orders\" & txt & "") Then

        MsgBox("Could not create the folder " & txt & " because it already exists.")

    Else

        My.Computer.FileSystem.CreateDirectory("\\ANVILSRV\Public\Completed Works Orders\" & txt & "")

        My.Computer.FileSystem.MoveFile(TextBox2.Text, ("\\ANVILSRV\Public\Completed Works Orders\" & txt & ""), True)

        My.Computer.FileSystem.MoveFile(TextBox3.Text, ("\\ANVILSRV\Public\Completed Works Orders\" & txt & ""), True)

    End If

End Sub

非常感谢任何建议或帮助。

谢谢

斯蒂芬

最佳答案

移动文件语法需要以下参数

sourceFileName = 源文件的完整路径

destinationFileName = 目标文件的完整路径

overWrite = bool 值,指定是否覆盖目标文件(如果已存在)

FileSystem.MoveFile(sourceFileName As String, destinationFileName As String, overWrite As Boolean)

在您的代码中,您没有指定参数 destinationFileName 的完整文件路径,而是指定了文件夹路径。在代码中给出完整的文件名,它就会起作用。例如“C:\Windows\DirectX.txt”

尝试以下代码

My.Computer.FileSystem.MoveFile(TextBox2.Text, ("\\ANVILSRV\Public\Completed Works Orders\" & txt & "\" & fileName), True)

关于.net - Visual Studio 2013 - 将文件移动到另一个路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33105855/

相关文章:

javascript - 在asp.net webform中添加一个jquery表单,需要使用php重定向到站点

c# - 将文件移动到另一个 Ftp 目录并重命名

powershell - 读取输入和移动具有相似名称的文件

powershell - 将文件向上移动一个文件夹级别

c# - C# 中的静态方法与实例方法

c# - .NET Core program.cs 和 Startup.cs 未命中

c# - 将 vb.net asp.net 代码转换为 C#

vb.net - 在没有管理员权限的情况下创建 VB.NET DLL

vb.net - System.Data.OracleClient 需要 Oracle 客户端软件版本 8.1.7

c# - 是否可以将图像存储到 pdf417 条码中?