阅读量:0
在VB中实现单个文件上传到文件夹可以使用以下代码:
Imports System.IO Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.Filter = "All files (*.*)|*.*" openFileDialog1.Multiselect = False If openFileDialog1.ShowDialog() = DialogResult.OK Then Dim selectedFile As String = openFileDialog1.FileName Dim folderPath As String = "C:\YourFolderPath\" ' 指定文件夹路径 Dim fileName As String = Path.GetFileName(selectedFile) Dim destinationFile As String = Path.Combine(folderPath, fileName) File.Copy(selectedFile, destinationFile) MessageBox.Show("File uploaded successfully.") End If End Sub End Class
在上面的代码中,首先创建一个OpenFileDialog
对象来选择要上传的文件,然后获取所选文件的路径并指定文件夹路径。接着使用File.Copy
方法将选择的文件复制到指定的文件夹中,并显示上传成功的消息框。