The remote server returned an error: (403) Forbidden

Aug 22 2018 6:55 AM
 
I am creating one small console application in C# to get the list name in the site. but I received this error message The remote server returned an error: (403) Forbidden.
Please help me to solve this issue.
 
This is the code i am using :
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Net;
using System.Security;
namespace CSOMCodeSamples
{
class Program
{
static void Main(string[] args)
{
string password = "Password";
ClientContext clientContext = new ClientContext("URL");
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
clientContext.Credentials = new NetworkCredential("UserName", securePassword, "Domain");
Web web = clientContext.Web;
ListCollection listColl = web.Lists;
clientContext.Load(listColl);
clientContext.ExecuteQuery();
foreach (List list in listColl)
{
// Display the list title and ID
Console.WriteLine("List Name: " + list.Title + "; ID: " + list.Id);
}
Console.ReadLine();
}
}
}
 
  

Answers (4)