2014-01-16 51 views
0

我無法從我的應用程序連接到Umbraco API,因爲「ConnectionString屬性尚未初始化」而出現錯誤。我已將cms.dll和businesslogic.dll作爲參考文件添加到Umbraco項目的我的應用程序中。如何調用Umbraco API

代碼:

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using umbraco.cms.businesslogic.member; 
using umbraco.cms.businesslogic.propertytype; 

namespace UmbracoCreateMember 
{ 
    public partial class Register : System.Web.UI.UserControl 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void btnRegister_Click(object sender, EventArgs e) 
     { 
      if (Member.GetMemberFromEmail(txtEmail.Text) == null) 
      { 
       MemberType demoMemberType = new MemberType(1040); //id of membertype 'demo' 
       Member newMember = Member.MakeNew(txtName.Text, demoMemberType, new umbraco.BusinessLogic.User(0)); 

       newMember.Email = txtEmail.Text; 
       newMember.Password = txtPassword.Text; 
       newMember.LoginName = txtUsername.Text; 

       newMember.getProperty("address").Value = txtAddress.Text; //set value of property with alias 'address' 
       newMember.getProperty("city").Value = txtCity.Text; //set value of property with alias 'city' 

       newMember.Save(); 
      }else 
      { 
       //member exists 
      } 
     } 
    } 
} 

截圖:

enter image description here

回答

1

您必須在Web.config文件中指定的一把umbraco實例

+0

是的ConnectionString,這個。這將是web.config –

+0

中連接字符串的問題,但連接字符串將如何連接umbraco項目。我以前用SQL服務器做過。但這是umbraco項目的第一次。我可以有樣品嗎? – kotis

+0

測試它:http://our.umbraco.org/forum/developers/api-questions/29269-How-I-can-get-connection-string-by-API –