TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kumar Sourabh
NA
294
1.3k
Not able to access Sharepoint O365 list from my Local System
Apr 24 2019 12:31 AM
I want to access sharepoint list from my local machine VS2012 using CSOM but getting The remote server returned an error: (401) Unauthorized. error message
My Code:
using
Microsoft.SharePoint.Client;
using
System;
using
System.Security;
using
System.Configuration;
namespace
SP_Console
{
class
Program
{
static
void
Main(
string
[] args)
{
ClientContext clientContext =
new
ClientContext(
"http://sphkcl.sharepoint.com/"
);
clientContext.Credentials =
new
SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
// Get the SharePoint web
Web web = clientContext.Web;
// Get the SharePoint list collection for the web
ListCollection listColl = web.Lists;
// Retrieve the list collection properties
clientContext.Load(listColl);
clientContext.ExecuteQuery();
// Loop through all the list
foreach
(List list
in
listColl)
{
// Display the list title and ID
Console.WriteLine(
"List Name: "
+ list.Title +
"; ID: "
+ list.Id);
}
Console.ReadLine();
}
private
static
SecureString GetSPOSecureStringPassword()
{
try
{
var secureString =
new
SecureString();
foreach
(
char
c
in
ConfigurationManager.AppSettings[
"SPPass"
])
{
secureString.AppendChar(c);
}
return
secureString;
}
catch
{
throw
;
}
}
private
static
string
GetSPOAccountName()
{
try
{
return
ConfigurationManager.AppSettings[
"SPAccount"
];
}
catch
{
throw
;
}
}
}
}
I have added username and password in app.config.
<
appSettings
>
<
add
key
=
"SPAccount"
value
=
"
[email protected]
"
/>
<
add
key
=
"SPPass"
value
=
"*********"
/>
</
appSettings
>
Reply
Answers (
2
)
To perform CRUD SPonprem lists using React with PNPjs SPFx
Convert [object(array)] in JSON