Skip to main content
added 885 characters in body
Source Link
Hardik Kothari
  • 996
  • 1
  • 11
  • 23

Yes there is Microsoft.SharePoint API used, using below c# code you can connect to SharePoint root site:

SPContext.Current.Site.URL

For subsites you can use the below code:

SPContext.Current.Web.URL

For ClientContext use the below code:

ClientContext context = new ClientContext("https://mycompany.sharepoint.com/sites/parts/");
        WindowsImpersonationContext ctx = null;
        if (!WindowsIdentity.GetCurrent().IsSystem)
        {
            ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
            // The SharePoint web at the URL.
            Web web = context.Web;

            // We want to retrieve the web's properties.
            context.Load(web);

            // Execute the query to the server.
            context.ExecuteQuery();

            // Now, the web's properties are available and we could display 
            // web properties, such as title. 
            System.Console.WriteLine("Web Title");
            System.Console.WriteLine(web.Title);
        }

Yes there is Microsoft.SharePoint API used, using below c# code you can connect to SharePoint root site:

SPContext.Current.Site.URL

For subsites you can use the below code:

SPContext.Current.Web.URL

Yes there is Microsoft.SharePoint API used, using below c# code you can connect to SharePoint root site:

SPContext.Current.Site.URL

For subsites you can use the below code:

SPContext.Current.Web.URL

For ClientContext use the below code:

ClientContext context = new ClientContext("https://mycompany.sharepoint.com/sites/parts/");
        WindowsImpersonationContext ctx = null;
        if (!WindowsIdentity.GetCurrent().IsSystem)
        {
            ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
            // The SharePoint web at the URL.
            Web web = context.Web;

            // We want to retrieve the web's properties.
            context.Load(web);

            // Execute the query to the server.
            context.ExecuteQuery();

            // Now, the web's properties are available and we could display 
            // web properties, such as title. 
            System.Console.WriteLine("Web Title");
            System.Console.WriteLine(web.Title);
        }
Source Link
Hardik Kothari
  • 996
  • 1
  • 11
  • 23

Yes there is Microsoft.SharePoint API used, using below c# code you can connect to SharePoint root site:

SPContext.Current.Site.URL

For subsites you can use the below code:

SPContext.Current.Web.URL