6

当我尝试使用 C# 程序使用 Sharepoint 提供的 UNC 路径将本地文件复制到 Sharepoint 服务器以访问文件系统时,我有一个奇怪的行为。首先,我的用户拥有访问该特定 Sharepoint 文件夹所需的所有权限。

这就是我的操作基本上是这样的:

string targetSharepointPath = @"\\team.mycompany.com@SSL\DavWWWRoot\team\wmscompanydep\Software Releases\MyToolConfig"
System.IO.File.Copy(sourcePath, targetSharepointPath, false);

此操作失败并显示错误“未找到网络路径”。

只要我复制上面的路径并将其粘贴到 Windows 文件资源管理器(不是Internet Explorer,这只是一个 UNC 路径),一切正常。

所以我的假设是,在后台,Windows 资源管理器会做更多的事情。但是什么?我不必输入任何凭据,targetSharepointPath 只需在资源管理器中工作,一旦输入一次,它也可以在我的 C# 程序中工作。在我重新启动系统之前,我必须重复该步骤。为什么,以及如何以编程方式实现这一目标?我经常在“普通”Windows 服务器上使用 UNC 路径,一旦用户拥有权限,我就不需要任何额外的身份验证。

4

1 回答 1

7

要连接到Sharepoint您需要一个名为WebClient.

当您从资源管理器中打开该链接时,它将确保该服务已启动。Sharepoint这可能是您在资源管理器中打开链接后能够从应用程序访问的原因。

您可以确保您的客户已经service自动启动以实现它。

或者您可以尝试以这种方式从您的代码中启动服务。(您可能需要管理员权限)

using (ServiceController service= new ServiceController("WebClient"))
    {

        if (service.Status == ServiceControllerStatus.Stopped)
        {

            service.Start();
            service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 15));
            //Check status here by calling service.Status and proceed with your code.
        }
        else
        {
          //proceed with your code as the service is up and running
        }
    }
于 2016-06-21T11:54:38.213 回答