5
如果只想保留文件,不想保留文件夹,可以改成如下代码:
private void lsReady_DragDrop(object sender, DragEventArgs e)
{
foreach (string filepath in (System.Array)e.Data.GetData(DataFormats.FileDrop))
{
if (File.Exists(filepath))
{
lsFiles.Items.Add(filepath);
}
}
}
如果是确定的某一个文件,直接用
Dim MyFullPath = System.IO.Path.GetFullPath(MyFileName)获得即可
如果是不确定的,可以采用dialog的方式,由用户自己选择来确定
FolderBrowserDialog获得文件夹的路径
Private Sub ButtonMSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMSelect.Click
Dim ofd As New FolderBrowserDialog
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.TextBoxMPath.Text = ofd.SelectedPath
Dim getDir() As String
getDir = IO.Directory.GetFiles(Me.TextBoxMPath.Text.ToString)
'得到路径下所有的文件的路径
End If
End Sub
获得文件路径用openfiledialog
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
filename2 = OpenFileDialog1.FileName
TextBox2.Text = System.IO.Path.GetFullPath(OpenFileDialog1.FileName)
End If
自己注意区分