I want to get the file from the office 365 share point using user credentials (have full access)
but while executing the program at runtime I'm getting the following error.
For this error I have read this post but not given the proper knowledge.
Microsoft.SharePoint.Client.ClientRequestException: 'Cannot contact site at the specified URL https://xxxx.sharepoint.com/sites/my_files/all%20Files. There is no Web named "/sites/my_files/all Files/_vti_bin/sites.asmx"
below is my code :
static void Main(string[] args)
{
string url = "https://xxxxx.sharepoint.com/sites/my_files/all%20Files";
string folderpath = "https://xxxxxxx.sharepoint.com/sites/my_files/all%20Files/Task";
string templocation = @"c:\Downloads\Sharepoint\";
Program.DownloadFilesFromSharePoint(url, folderpath, templocation);
}
static void DownloadFilesFromSharePoint(string siteUrl, string siteFolderPath, string localTempLocation)
{
string userName = "aaaa@xxxxxx.com";
string pswd = "ssssss@1043";
SecureString password = new SecureString();
foreach (var c in pswd.ToCharArray()) password.AppendChar(c);
var ctx = new ClientContext(siteUrl);
//ctx.Credentials = new NetworkCredential(userName, password, "smtp-mail.outlook.com");
ctx.Credentials = new SharePointOnlineCredentials(userName, password);
FileCollection files = ctx.Web.GetFolderByServerRelativeUrl(siteFolderPath).Files;
ctx.Load(files);
if (ctx.HasPendingRequest)
{
ctx.ExecuteQuery(); //getting error here : Cannot contact site at the specified URL. There is no Web named "*.asmx"
}
foreach (File file in files)
{
FileInformation fileInfo = File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);
ctx.ExecuteQuery();
var filePath = localTempLocation + "\\" + file.Name;
System.IO.FileStream fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
fileInfo.Stream.CopyTo(fileStream);
}
}
Suggest me how to achieve this and what is the issue ?