通过SSL连接到Site文件夹

时间:2014-04-25 18:43:20

标签: c# ssl webdav

好的,这对我来说很难解决,但让我解释一下发生了什么。我有一个使用https的sharepoint(可能不相关)网站。我写了一个c#程序从该站点的文件夹下载文件。我到该文件夹​​的路径是

string pathA = @"\\mysite.com@SSL\DavWWWRoot\sites\abc\Lists\Images\Screen Slides\";

所以问题是当你启动你的机器时,代码会抛出错误:找不到文件夹。我的解决方法是让C#程序打开文件夹需要两个步骤,我不知道如何编码。我将该URL打开为运行命令,它会说它无法连接第一次尝试。然后我再次运行它将连接。因此需要两个运行命令才能连接到该文件夹​​。在此之后,C#程序将无法找到并访问该文件夹。

我的猜测是我需要使用某种凭据来连接我的C#代码,而无需进行解决。我正在寻找一种使用代码连接到网站的方法,这样用户就不必更改其计算机上的任何设置。感谢

编辑:以下是将SSL文件夹与本地directoy进行比较的代码。从那里它将下载或删除文件

string pathA = @"\\mysite.com@SSL\DavWWWRoot\sites\abc\Lists\Images\Screen Slides\";
string pathB = imagepath;

System.IO.DirectoryInfo dir1 = new System.IO.DirectoryInfo(pathA);
System.IO.DirectoryInfo dir2 = new System.IO.DirectoryInfo(pathB);

// Take a snapshot of the file system.
IEnumerable<System.IO.FileInfo> list1 = dir1.GetFiles("*.*", System.IO.SearchOption.TopDirectoryOnly);
IEnumerable<System.IO.FileInfo> list2 = dir2.GetFiles("*.*", System.IO.SearchOption.TopDirectoryOnly);

//A custom file comparer defined below
FileCompare myFileCompare = new FileCompare();

// Find the set difference between the two folders. 
// Check if there is new images in network drive and if not download to C. 
var queryList1Only = (from file in list1
      select file).Except(list2, myFileCompare);

Console.WriteLine("The following files are in list1 but not list2:");
foreach (var v in queryList1Only)
{
    File.Copy(v.FullName, Path.Combine(pathB, v.Name));
    Console.WriteLine("Download done");
    Console.WriteLine(v.FullName);
}

// Find the set difference between the two folders. 
// Check if there is old images in C drive and if so delete them. 
var queryList2Only = (from file in list2
      select file).Except(list1, myFileCompare);

Console.WriteLine("The following files are in C:/ but not \\share:");
foreach (var v in queryList2Only)
{  
    File.Delete(v.FullName);
    Console.WriteLine("Delete done");
    Console.WriteLine(v.FullName);
}

// Keep the console window open in debug mode.
Console.WriteLine("File Sync Done");

0 个答案:

没有答案