Cannot contact site at the specified URL. There is no Web named "*.asmx" error in console application c#

Ashok Kumar 201 Reputation points
2022-10-17T12:48:24.807+00:00

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 ?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,884 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,397 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 32,241 Reputation points Microsoft Vendor
    2022-10-18T01:40:41.123+00:00

    Hi @Ashok Kumar
    In your case, the site url should be like https://xxxxxxx.sharepoint.com/sites/my_files. The url you connect is the path of the document library but not a site. So the error message said There is no Web named "*.asmx".
    You could change the code in main function like following

      string url= "https://xxxxx.sharepoint.com/sites/my_files";  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful