2016-07-11 57 views
0

我正在開發一個通過Azure應用程序服務的SharePoint加載項(用於Sharepoint Online [Office 365]環境中)。我正在嘗試爲某些目標創建一個站點管理器。我已經發布了加載項,可以訪問我的ASP.Net頁面。我正在使用Microsoft.Sharepoint庫(來自NuGet)。當我嘗試添加該網站,我得到了以下錯誤:從ASP.NET失敗中將網站添加到SharePoint Online

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.

這是後面的代碼我使用:

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(); 
      } 
     } 
    } 
} 

誰能告訴我,我是什麼做錯了?

回答

0

在visual studio中展開參考文件夾,選擇程序集「Microsoft.SharePoint.Library」並按F4,然後將Copy Local的值更改爲true。

+0

所有引用都將copy local選項設置爲true。這就像Microsoft.SharePoint.Library不是Microsoft.SharePoint DLL的一部分。 –

+0

我從來沒有見過這個DLL,你在用它嗎? –

+0

不,我認爲這是主要Microsoft.SharePoint DLL的依賴性。我的代碼在我的問題中沒有做任何描述。 –

相關問題