Eri*_*rik 5 c# sharepoint unc file-copying system.io.file
当我尝试使用C#程序使用Sharepoint提供的UNC路径将本地文件复制到Sharepoint Server以访问文件系统时,我有一种奇怪的行为.首先,我的用户拥有访问该特定Sharepoint文件夹所需的所有权限.
这是我的操作基本上是这样的:
string targetSharepointPath = @"\\team.mycompany.com@SSL\DavWWWRoot\team\wmscompanydep\Software Releases\MyToolConfig"
System.IO.File.Copy(sourcePath, targetSharepointPath, false);
Run Code Online (Sandbox Code Playgroud)
此操作失败,并显示错误"未找到网络路径".
一旦我复制上面的路径并将其粘贴到WIndows文件资源管理器(不是 Internet Explorer,这只是一个UNC路径),一切正常.
所以我的假设是,在后台,Windows资源管理器做了一点点.但是什么?我不必输入任何凭据,targetSharepointPath只能在资源管理器中使用,一旦输入一次,它也可以在我的C#程序中运行.在我重新启动系统之前,我必须重复这一步.为什么,以及如何以编程方式实现这一目标?我在"普通"Windows服务器上使用UNC路径很多,一旦用户拥有权限,我就不需要任何额外的身份验证.
要连接到Sharepoint您需要一个名为的Windows服务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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
707 次 |
| 最近记录: |