0

SharePoint 2007サーバー上のフォルダーをバックアップし、その場所にファイルの新しいコピーを配置するVB.netアプリケーションを作成しました。このアプリケーションは私のWindows7コンピューターで完全に機能しますが、同僚がWindows XPコンピューターで実行すると、多くのエラーが発生します。私はそれらを解決するかもしれないので試してみてください、私はただできません。

最初のエラーは、DirectoryInfo変数を暗くしたときです。SharePointサーバーのWebDavフォルダーに接続します。ユーザーが最初にドライブを手動でUNCにマップしない限り(通常のログオンを使用し、特別な資格情報は使用しない)、アクセス拒否エラーが発生するようです。私には回避策があるので、これは重要ではありませんが、解決策があれば役立つでしょう。

2番目の(そして最も重要な)エラーは、ファイルのコピー中にWindowsXPコンピュータで「遅延書き込み失敗」エラーが発生することです。このエラーを受け取ったファイルは適切にバックアップされません。このエラーは、プログラムの実行を停止することさえありません!これを解決する方法はありますか?

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click

    ' Dim all variables
    Dim i, countfiles As Integer
    Dim CompletedReports As New DirectoryInfo(GlobalVariables.ServerURL)
    Dim dNow As Date = Date.Today
    Dim friday As Date
    Dim friD, friM, friY, archiveFolder, archiveURL As String
    Dim FreshReports As New DirectoryInfo(GlobalVariables.ServerURL + "\Report Archive\Templates\")

    ' Prevent form from being closed while running
    btnDone.Enabled = False
    btnGo.Enabled = False
    btnRunSetup.Enabled = False
    Application.DoEvents()

    ' Calculate the archive date
    friday = dNow.AddDays(-(CInt((dNow.DayOfWeek + 1) Mod 7) + 1))
    friD = friday.Day
    friM = friday.Month
    friY = friday.Year
    If Len(friD) < 2 Then
        friD = "0" + friD
    End If
    If Len(friM) < 2 Then
        friM = "0" + friM
    End If
    archiveFolder = friY + "-" + friM + "-" + friD

    archiveURL = GlobalVariables.ServerURL + "\Report Archive\" + archiveFolder

    ' Count number of files in the current folder
    RecursiveCount(CompletedReports, i)

    ' Do the SharePoint Archive to the "Report Archive" folder
    countfiles = i
    PB_SharePointArchive.Maximum = i
    PB_SharePointArchive.Step = 1
    CopyDirectory(GlobalVariables.ServerURL, archiveURL, PB_SharePointArchive, LB_SharePointArchive_Name, False)
    LB_SharePointArchive_Name.Text = "Done!"

    ' If specified, do the Server Backup
    If GlobalVariables.RemoteBackup = True Then
        i = countfiles
        PB_RemoteBackup.Maximum = i
        PB_RemoteBackup.Step = 1
        CopyDirectory(GlobalVariables.ServerURL, GlobalVariables.RemotePath + archiveFolder, PB_RemoteBackup, LB_RemoteBackup_Name, False)
        LB_RemoteBackup_Name.Text = "Done!"
    End If

    ' If specified, do the Local Backup
    If GlobalVariables.LocalBackup = True Then
        i = countfiles
        PB_LocalBackup.Maximum = i
        PB_LocalBackup.Step = 1
        CopyDirectory(GlobalVariables.ServerURL, GlobalVariables.LocalPath + archiveFolder, PB_LocalBackup, LB_LocalBackup_Name, False)
        LB_LocalBackup_Name.Text = "Done!"
    End If

    ' Refresh the Reports
    i = 0
    RecursiveCount(FreshReports, i)
    PB_SharePointRefresh.Maximum = i
    PB_SharePointRefresh.Step = 1
    CopyDirectory(GlobalVariables.ServerURL + "\Report Archive\Templates\", GlobalVariables.ServerURL, PB_SharePointRefresh, LB_SharePointRefresh_Name, True)
    LB_SharePointRefresh_Name.Text = "Done!"

    ' All tasks done - unlock the close function
    btnDone.Enabled = True

End Sub


Private Sub CopyDirectory(ByVal sourceDir As String, ByVal destDir As String, ByRef progBar As ProgressBar, ByRef statusBox As Label, ByVal overwrite As Boolean)

    Dim prompt, retry

    If Not Directory.Exists(destDir) Then
        Directory.CreateDirectory(destDir)
    ElseIf Directory.Exists(destDir) And overwrite = False Then
        'MsgBox("The directory already exists!" + vbCrLf + "It looks like the backup has already been done for this week." + vbCrLf + "To continue, please delete the previous backup and restart the process", MsgBoxStyle.Critical, "TSO Report Refresh")

        prompt = MsgBox("The directory already exists!" + vbCrLf + "It looks like the backup has already been done for this week." + vbCrLf + "Do you wish to delete the previous backup?", MsgBoxStyle.YesNo, "TSO Report Refresh")
        If prompt = vbYes Then
            DeleteDirectory(destDir)
            Directory.CreateDirectory(destDir)
        Else
            MsgBox("You have chosen not to delete the previous backup. Backup cannot continue." + vbCrLf + "To continue, please delete the previous backup and restart the process", MsgBoxStyle.Critical, "TSO Report Refresh")
        End If
    End If

    For Each strEntry As String In Directory.GetFiles(sourceDir)
        Dim fileNew As FileInfo
        fileNew = New FileInfo(strEntry)

        If fileNew.Exists Then
            retry = 3
            statusBox.Text = "Current File: " + fileNew.Name
            Application.DoEvents()
            While retry > 0
                Try
                    fileNew.CopyTo(destDir & "\" & fileNew.Name, True)
                    retry = 0
                    progBar.PerformStep()
                    Application.DoEvents()
                Catch ex As Exception
                    retry = retry - 1
                    If retry = 0 Then
                        MsgBox("A file has failed to copy after three attempts. The application will now close." + vbCrLf + fileNew.Name, MsgBoxStyle.Critical, "TSO Report Refresh")
                        End
                    End If
                    'Debug.Print("Retrying file " + fileNew.Name + " for the " + (3 - retry) + " time...")
                End Try
            End While
        End If
    Next

    For Each strEntry As String In Directory.GetDirectories(sourceDir)
        If Path.GetFileName(strEntry) = "Report Archive" Or Path.GetFileName(strEntry) = "Forms" Then
            'Do Nothing!
        Else
            Dim strDest As String = Path.Combine(destDir, Path.GetFileName(strEntry))
            CopyDirectory(strEntry, strDest, progBar, statusBox, overwrite)
        End If
    Next

End Sub
4

0 に答える 0