VB.net从桌面移动文件

VB.net从桌面移动文件,vb.net,Vb.net,我正在为一个模组制作一个发射器。我有一切我需要的工作。问题是,不管怎样,在我给其他用户后,启动器可以从他们的桌面上移动东西,因为我知道不是每个人在他们的用户文件中都有相同的名称,所以他们是一种全局方式,可以访问别人的桌面,而必须为每个人更改它。就像我的桌面位于C:\Users\Zach\desktop一样,不是每个人的用户文件都是Zach,这是我目前所有的代码。我也在寻求帮助,而不是别人帮我 Public Class Form1 Private Sub PictureBox1_Click(By

我正在为一个模组制作一个发射器。我有一切我需要的工作。问题是,不管怎样,在我给其他用户后,启动器可以从他们的桌面上移动东西,因为我知道不是每个人在他们的用户文件中都有相同的名称,所以他们是一种全局方式,可以访问别人的桌面,而必须为每个人更改它。就像我的桌面位于C:\Users\Zach\desktop一样,不是每个人的用户文件都是Zach,这是我目前所有的代码。我也在寻求帮助,而不是别人帮我

Public Class Form1

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    Me.Close()
End Sub

Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    PictureBox1.Image = My.Resources.Exit_2
End Sub

Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    PictureBox1.Image = My.Resources._Exit
End Sub

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    Process.Start("FILE NAME")
    MsgBox("Downloading Arma 3 Mods")
End Sub

Private Sub PictureBox2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseEnter
    PictureBox2.Image = My.Resources.Download_2

End Sub

Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseLeave
    PictureBox2.Image = My.Resources.Download
End Sub

Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
    Dim path As String = "c:\"
    Dim path2 As String = "c:\"

    Try
        If File.Exists(path) = False Then
            ' This statement ensures that the file is created, 
            ' but the handle is not kept. 
            Dim fs As FileStream = File.Create(path)
            fs.Close()
        End If

        ' Ensure that the target does not exist. 
        If File.Exists(path2) Then
            File.Delete(path2)
        End If

        ' Move the file.
        File.Move(path, path2)
        Console.WriteLine("{0} moved to {1}", path, path2)

        ' See if the original file exists now. 
        If File.Exists(path) Then
            Console.WriteLine("The original file still exists, which is unexpected.")
        Else
            Console.WriteLine("The original file no longer exists, which is expected.")
        End If
    Finally
    End Try
End Sub


Private Sub PictureBox3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseEnter
    PictureBox3.Image = My.Resources.Move_File_2
End Sub

Private Sub PictureBox3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseLeave
    PictureBox3.Image = My.Resources.Move_File
End Sub
End Class

您可以使用Environment.GetFolderPath方法:


在这种情况下,使用
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
为用户获取桌面目录

像这样:

Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
   End Sub 'Main
End Class 'Sample

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
当我去调用桌面上的文件时,另一个问题是我应该在C之后放什么:/use
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),文件名
要获得桌面上文件的完全限定路径名,我应该在Dim path上放置什么路径作为String=“C:\”您不添加到C:\我给您的代码是为您做的。我应该将它放在哪里?现在我把它放在底部了。