0
votes

I'm developing a SharePoint Add-In throught Azure App Services (for usage within a Sharepoint Online [Office 365] Environment). I'm trying to create a Site Manager for certain perposes. I've published the add-in and can reach my ASP.Net page. I'm using the Microsoft.Sharepoint library (from NuGet). When I'm trying to add the site, I'm getting the following error:

Could not load file or assembly 'Microsoft.SharePoint.Library, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

This is the code behind i'm using:

public void AddWebsite(string siteUrl, string title)
{
    using (SPSite site = new SPSite(siteUrl))
    {
        string parentWebName = ""; //here I set the parent webname (left in blank for now)

        using (SPWeb parentWeb = site.OpenWeb(parentWebName))
        {
            string webTitle = title;
            string webDesc = "This site is created by ... | SiteName: " + title;

            Regex rgx = new Regex("[^a-zA-Z0-9 -]");
            string webName = rgx.Replace(title, "");

            string webUrl = String.Format("{0}/{1}", parentWebName, webName);
            uint webLcid = parentWeb.Language;

            string webTemplateName = "STS#2";

            SPWeb newWeb = null;

            try
            {
                newWeb = site.AllWebs.Add(webUrl, webTitle, webDesc, webLcid, webTemplateName, false, false);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (newWeb != null)
            {
                newWeb.Navigation.UseShared = true;

                SPNavigationNode node = new SPNavigationNode(newWeb.Title, newWeb.ServerRelativeUrl);

                bool parentInheritsTopNav = newWeb.ParentWeb.Navigation.UseShared;

                if (parentInheritsTopNav)
                    site.RootWeb.Navigation.TopNavigationBar.AddAsLast(node);
                else
                    newWeb.ParentWeb.Navigation.TopNavigationBar.AddAsLast(node);

                newWeb.Dispose();
            }
        }
    }
}

Can anybody tell me what I'm doing wrong?

1

1 Answers

0
votes

Expand reference folder in visual studio, select assembly "Microsoft.SharePoint.Library" and press F4 then change the value of Copy Local to true.