MS Access VBA 确定 SharePoint 文件夹是否可访问

MS Access VBA determine if a SharePoint folder is accessible

是否有可靠的方法来确定当前是否可以访问 SharePoint 文件夹?我正在使用 UNC 路径,即“\\mycompany\mySharePoint\mySite\myFolder”

我正在使用 FileSystemObject.FolderExists:

    If Not fso.FolderExists(uncFolder) Then
    MsgBox "SharePoint folder not found. Cannot connect to folder, or folder does not exist. SharePoint URL required for report: """ & uncFolder & """", vbCritical, "Folder not found"
    GoTo exitHandler
    End If

问题是这不能可靠地工作。如果用户是无线连接的,或者是第一次连接到文件夹,则连接、身份验证和打开可能需要长达五秒钟的时间。 FolderExists 函数可以在此之前超时并且 return 假阴性。

是否有可靠的方法来确保用户能够连接或不连接?我正在使用出色的 DoCmd.OutputTo acReport ... acFormatPDF 来自动打印多个报告并将它们保存到 SharePoint。但是在尝试打印和保存之前,我必须确保用户能够连接。

谢谢!!

不确定,但这可能有效..尝试使用 xmlhttp 对象读取页面,这应该等待状态...设置对 Microsoft XML 的引用,或者如果您愿意,可以进行后期绑定..

Function TestURL(url As String) As Boolean
 On Error GoTo errhandler
    Dim httpObject As New XMLHTTP
    With httpObject
      .Open "GET", url, False
      .send
      If .ReadyState = 4 And .Status = 200 Then TestURL = True
    End With
   Set httpObject = Nothing
 Exit Function
errhandler:   Debug.Print "TestURL", Err.Description
End Function

所以你可以检查,并在必要时继续检查,直到这个函数 returns 为真,如果你需要的话,在开始导出之前在两者之间休眠...

Sharepoint 是文件系统上的一层 HTML 形式,可以将 Sharepoint 使用的 URLs 转换为常规 Windows 文件系统地址。

所以你需要这样的东西:

sFolderPath = TidyFilePath(SharepointFolderURL)
以及对 Scripting.FileSystemObject 的普通调用以检查结果:


Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.FolderExists(sFolderPath)
这是 URL 翻译器...

VBA URL SharePoint 文件夹路径的翻译器:

Public Function TidyFilePath(strPath As String) As String
' Translate file paths from sharepoint into WinFS paths
strPath = Trim(strPath)
strPath = Replace(strPath, "/", "/") strPath = Replace(strPath, "%2F", "/") strPath = Replace(strPath, "/", "\") strPath = Replace(strPath, "\", "\") strPath = Replace(strPath, "%5C", "\") strPath = Replace(strPath, "%20", " ") strPath = Replace(strPath, " ", " ") strPath = Replace(strPath, " ", " ") strPath = Replace(strPath, "%A0", " ") strPath = Replace(strPath, Chr(160), " ") strPath = Replace(strPath, "<", "") strPath = Replace(strPath, ">", "")
If Left(strPath, 7) = "http:\" Then strPath = Replace(strPath, "http:\", "", 1) ElseIf Left(strPath, 8) = "https:\" Then strPath = Replace(strPath, "https:\", "", 1) ElseIf Left(strPath, 6) = "ftp:\" Then strPath = Replace(strPath, "ftp:\", "", 1) ElseIf Left(strPath, 7) = "ftps:\" Then strPath = Replace(strPath, "ftps:\", "", 1) End If
TidyFilePath = strPath
End Function
我确信某个地方的某个人已经发布了一个明确的翻译器,它捕获了将 Windows 网络路径变为有效 URL 所需的所有 HTML 实体。它可能存在于 System32 的库中,要是我知道去哪里找就好了...

...任何 .NET 和 Ruby 开发人员都会挠头* 并想知道“这是怎么回事?这是怎么回事?甚至可能是一个问题?”,因为大多数现代语言都以您从未见过甚至想都没想过的水平为您完成所有这些工作。





* 通过谨慎选择用词,我避免了对负责人与开发人员比例的不礼貌假设。我们仍然没有弄清楚他们把巨大的大脑放在哪里。