Connect to sharepoint on premise site from my asp net

Introduction

to a on-premise site from an ASP.NET application can be a challenging task. However, with the right approach and understanding of the ASP.NET programming language, it is possible to establish a and interact with SharePoint data seamlessly. In this article, we will explore different methods and examples to achieve this.

Using SharePoint Client Object Model

The SharePoint Client Object Model (CSOM) provides a set of libraries that allow developers to interact with SharePoint remotely. To to a SharePoint on-premise site from an ASP.NET application using CSOM, you need to follow these steps:

Step 1: Add References

First, you need to add the necessary references to your ASP.NET project. These references include:


using Microsoft.SharePoint.Client;

Step 2: Establish Connection

Next, you need to establish a connection to the SharePoint site by providing the site URL and credentials. Here's an example:


string siteUrl = "http://yoursharepointsite";
string username = "yourusername";
string password = "yourpassword";

ClientContext context = new ClientContext(siteUrl);
context.Credentials = new NetworkCredential(username, password);

Step 3: Interact with SharePoint Data

Once the connection is established, you can perform various operations on SharePoint data. For example, you can retrieve a list of documents from a document library:


List documentsList = context.Web..GetByTitle("Documents");
context.Load(documentsList);
context.ExecuteQuery();

foreach (ListItem document in documentsList.)
{
    Console.WriteLine(document["FileLeafRef"]);
}

Using SharePoint Web Services

Another approach to connect to a SharePoint on-premise site from an ASP.NET application is by using SharePoint Web Services. These services provide a way to interact with SharePoint using SOAP-based web methods. Here's an example:

Step 1: Add Web References

First, you need to add the necessary web references to your ASP.NET project. These references include:


using System.Web.Services;
using System.Web.Services.Protocols;

Step 2: Create Service

Next, you need to create a service proxy to connect to the SharePoint site. Here's an example:


string siteUrl = "http://yoursharepointsite";
string username = "yourusername";
string password = "yourpassword";

Lists listsService = new Lists();
listsService.Url = siteUrl + "/_vti_bin/Lists.asmx";
listsService.Credentials = new NetworkCredential(username, password);

Step 3: Interact with SharePoint Data

Once the service proxy is created, you can call various web methods to interact with SharePoint data. For example, you can retrieve a list of documents from a document library:


XmlNodeList documents = listsService.GetListItems("Documents", null, null, null, null, null, null);
foreach (XmlNode document in documents)
{
    Console.WriteLine(document.Attributes["ows_FileLeafRef"].);
}

Conclusion

Connecting to a SharePoint on-premise site from an ASP.NET application understanding the ASP.NET programming language and utilizing the appropriate methods and libraries. In this article, we explored two approaches: using SharePoint Client Object Model (CSOM) and SharePoint Web Services. Both methods allow developers to establish a connection and interact with SharePoint data effectively. By following the provided examples, you can successfully connect to a SharePoint on-premise site and leverage its capabilities in your ASP.NET application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents