Using Windows form to remote/ active/ Claims based authenticate to on premises MS SharePoint 2013 website in C#

StackOverflow https://stackoverflow.com/questions/23096707

  •  04-07-2023
  •  | 
  •  

Question

How do I use Windows form to remote/ active/ Claims based authenticate to an on - premises MS SharePoint 2013 website in C#? Please I'm new to SharePoint 2013 App Dev so I would appreciate clear and simple steps on how to accomplish this task.

Regards

Here is another attempt but no luck

  private void btnLogin_Click(object sender, EventArgs e)
    {

        try
        {

            string webUrl = textBox1.Text;


            string userName = txtBxUN.Text;

            string password = txtBxPW.Text;
            using (var context = new ClientContext(webUrl))
            {
                var secure = new SecureString();
                foreach (char c in password)
                {
                    secure.AppendChar(c);
                }
                // get error the 'username' argument is invalid when i try to login to on-premises SharePoint 2013 website 
                context.Credentials = new SharePointOnlineCredentials(userName, secure);
                context.Load(context.Web, w => w.Title);
                context.ExecuteQuery();

                MessageBox.Show("Your site title is: " + context.Web.Title);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

        }
    }
Was it helpful?

Solution

The solution to this problem was multi - tier in nature.

  1. Created a service reference to the target document library in SharePoint

  2. Create an instance of the service and use windows active directory as the credentials

  3. Use Client Side Object Model to work its magic.

Done!

 var dc = new subsiteDataContext(new Uri("http://.../subsite/_vti_bin/ListData.svc"))
            {
                Credentials = System.Net.CredentialCache.DefaultCredentials
            };

Insert your CSOM code here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top