2

I'm trying to access a SharePoint site from an Application created on Visual Studio, this application will pass credentials against the SharePoint site. The application will then be able to create specific tasks.

There something I'd like to mention,

  • I don't own any part of the SharePoint site
  • I just have an account to access the site (As a user it allows me to create Task/Issues

To understand what I'm trying to do you'd need to just think of it this way, you've found a SharePoint site that you enjoy using, you have no access to this sites server or admin right (You're just a regular user). You'd like to automate something for that site by creating an application on Visual Studio.

How would you go about doing this, if you still need some more information or explanation please do ask.

2

You have to use the Client Side object model.

These are the options available.

  • .NET Framework redistributable assemblies
  • JavaScript library
  • REST/OData endpoints
  • Windows Phone assemblies
  • Silverlight redistributable assemblies

Here I have posted some basic operations using JavaScript. get the web object using url and rest of the code will be same.

2

You can do like this

private static void InsertToList(SiteUrl)
    { 
         using (ClientContext clientContext = new ClientContext(SiteUrl))
            {
                if (WindowsAuth)
                {
                    NetworkCredential credentials = new NetworkCredential(SPUserName, SPPassword);
                    clientContext.Credentials = credentials;
                    clientContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(clientContext_ExecutingWebRequest);
                }
                else
                {
                    System.Net.ServicePointManager.Expect100Continue = false;
                    clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                    clientContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(SPUserName, SPPassword);
                }
                List MyList = clientContext.Web.Lists.GetByTitle(ListName);
                ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
                ListItem itm = MyList.AddItem(listCreationInformation);
                itm["Title"] = "Test Title"
                itm.Update();
                clientContext.ExecuteQuery();
            }
   }
   static void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs  e)
    {
        e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
    }

You need to add reference of Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime

Hope this helps you

Thanks

0

You have 03 options to do this type of developments. In CSOM, there are different flavors - Silverlight, Windows Forms, JavaScript. Depending on your selection, you can connect with SharePoint and perform any activity using one of the above flavors of CSOM.

  • Do you have any examples or tutorials on this? @Joy_Rathnayake – Prosperity Aug 22 '14 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.