在VB.net中将PDF文件上载到服务器

时间:2013-09-08 12:34:31

标签: asp.net vb.net pdf file-upload web

我有一个基于网络的应用程序我需要添加新的功能是将PDF文件从DVD上传到服务器中的文件夹位置。

像这样的DVD结构 1-文件夹12072013 2-在同一级别有CSV文件和名为Images的文件夹。

我需要上传已完成的CSV文件中的数据,我需要上传PDF文件 还可以在Images文件夹中输入,将其从DVD复制到服务器中的文件夹。

1 个答案:

答案 0 :(得分:0)

Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, Optional ByVal Overwrite As Boolean = True)
    Application.DoEvents()
    Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath)
    Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)

    ' the source directory must exist, otherwise throw an exception
    If SourceDir.Exists Then
        ' if destination SubDir's parent SubDir does not exist throw an exception
        If Not DestDir.Parent.Exists Then
            Throw New DirectoryNotFoundException _
                ("Destination directory does not exist: " + DestDir.Parent.FullName)
        End If

        If Not DestDir.Exists Then
            DestDir.Create()
        End If

        ' copy all the files of the current directory
        Dim ChildFile As FileInfo
        For Each ChildFile In SourceDir.GetFiles()
            If Overwrite Then
                ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)
            Else
                If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then
                    ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), False)
                End If
            End If
        Next

        ' copy all the sub-directories by5 recursively calling this same routine
        Dim SubDir As DirectoryInfo
        For Each SubDir In SourceDir.GetDirectories()
            CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, _
                SubDir.Name), Overwrite)
        Next
    Else
        Throw New DirectoryNotFoundException("Source directory does not exist: " + SourceDir.FullName)
    End If
End Sub
相关问题