将多个文件上载到vb.net中的本地文件夹
我试图创建一个功能,允许用户上传多个文件到一个本地文件夹 目前我只能上传一个文件。我需要一次上传更多的文件 用于打开文件/文件夹的内容将多个文件上载到vb.net中的本地文件夹,vb.net,file-upload,vb.net-2010,Vb.net,File Upload,Vb.net 2010,我试图创建一个功能,允许用户上传多个文件到一个本地文件夹 目前我只能上传一个文件。我需要一次上传更多的文件 用于打开文件/文件夹的内容 a.Multiselect = True If a.ShowDialog() = Windows.Forms.DialogResult.OK Then removeatt.Show() removeatt.Text = "Remove Attachment" fpath.Text = a.FileName
a.Multiselect = True
If a.ShowDialog() = Windows.Forms.DialogResult.OK Then
removeatt.Show()
removeatt.Text = "Remove Attachment"
fpath.Text = a.FileName
address.Text = System.IO.Path.GetFileName(a.FileName)
Dim file As String
file = fpath.Text.ToString
Label7.Text = file
If fpath.Text = "-" Then
removeatt.Hide()
Else
removeatt.Show()
End If
End If
我使用什么来保存附件
If fpath.Text = "-" Then
Else
My.Computer.FileSystem.CopyFile(fpath.Text = "-", dir2 + Upload.Label16.Text, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
End If
谢谢你的帮助
谢谢我不完全清楚您在哪里处理所选文件,第一个是关于删除附件,保存部分不是关于上载,它会像看起来那样将文件保存到用户的磁盘上 通常,我建议您编写一个函数,一次处理一个文件,这样您就可以在for each循环中向函数提供要复制的文件列表。这个函数有点“基本”来说明我的意思
Public Function CopyToDisk(ByVal DestinationPath As String, ByVal Sourcepath As String) As String
If Not System.IO.File.Exists(Sourcepath) Then
Return "Source missing" & Sourcepath
End If
Try
File.Copy(Sourcepath, DestinationPath)
Catch ex As Exception
Return ex.Message
End Try
Return "ok"
End Function
好的,看看MSDN这里的例子,它有一个文件选择器,然后它把对象放在一个数组中,你可以循环并复制到你想复制的地方 MSDN是原件吗 公开课表格1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeOpenFileDialog()
End Sub
Private Sub Selectfilebutton_Click_1(sender As Object, e As EventArgs) Handles Selectfilebutton.Click
Dim dr As DialogResult = Me.OpenFileDialog1.ShowDialog()
If (dr = System.Windows.Forms.DialogResult.OK) Then
' Read the files
Dim file As String
For Each file In OpenFileDialog1.FileNames
'' you can loop through the array of objects and use a function to do the copying
' so for instance with my function it would be :
' copytodisk(Destination, file.filename)
' Create a PictureBox for each file, and add that file to the FlowLayoutPanel.
Try
Dim pb As New PictureBox()
Dim loadedImage As Image = Image.FromFile(file)
pb.Height = loadedImage.Height
pb.Width = loadedImage.Width
pb.Image = loadedImage
FlowLayoutPanel1.Controls.Add(pb)
Catch SecEx As SecurityException
' The user lacks appropriate permissions to read files, discover paths, etc.
MessageBox.Show("Security error. Please contact your administrator for details.\n\n" & _
"Error message: " & SecEx.Message & "\n\n" & _
"Details (send to Support):\n\n" & SecEx.StackTrace)
Catch ex As Exception
' Could not load the image - probably permissions-related.
MessageBox.Show(("Cannot display the image: " & file.Substring(file.LastIndexOf("\"c)) & _
". You may not have permission to read the file, or " + "it may be corrupt." _
& ControlChars.Lf & ControlChars.Lf & "Reported error: " & ex.Message))
End Try
Next file
End If
End Sub
Public Sub InitializeOpenFileDialog()
' Set the file dialog to filter for graphics files.
Me.OpenFileDialog1.Filter = _
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + _
"All files (*.*)|*.*"
' Allow the user to select multiple images.
Me.OpenFileDialog1.Multiselect = True
Me.OpenFileDialog1.Title = "My Image Browser"
End Sub
我想将不同文件夹中的多个文件保存到新文件夹中,以便使用“打开”对话框的“多选”方法使其更有条理。但我不知道如何将选定的项目一次性保存到新文件夹我想将文件从可移动设备或磁盘上的其他文件夹复制或保存到磁盘上的另一个文件夹以组织文件或附件,我需要它来处理多个选定的文件