2010-02-10 5 views
1

셰어 포인트 컨트롤을 사용하려면 SPContext.current.site/web이 작동해야하지만 site = new spsite (siteID); 나는 컨트롤을 사용하고 싶다. 그래서 어떤 생각이나 사용 가능한 클래스를 sharepoint에서 asp.net 컨트롤을 사용합니까? 내가 사용하고spcontext.current를 사용하지 않고 셰어 포인트에서 컨트롤을 사용하는 방법

+0

제어 개체를 만드는 방법과 사용하려고 할 때 어떤 예외가 발생하는지 등의 자세한 정보를 제공해주십시오. 감사합니다. –

+0

답장에 답글을 쓸 것입니다. 답장이 너무 커서 – Manale

답변

0
//open site and web 
sSiteID = Request.QueryString["siteID"]; 
sWebID = Request.QueryString["parentWebID"]; 
site = new SPSite(new Guid(sSiteID)); 
web = site.OpenWeb(new Guid(sWebID)); 
//show the properties of the list in the edit form 
(...) 
if ((list.AllowContentTypes == true) && (list.ContentTypesEnabled == true)) 
{ 
    (...) 
    SharePointWebControls oSharePointWebControls = new SharePointWebControls(); 

    cntrl = oSharePointWebControls.GetSharePointControls(field, list, item, SPControlMode.Edit, ""); 
} 

public Control GetSharePointControls(SPField field, SPList list, SPListItem item, SPControlMode mode, string strType) 
{ 
    switch (field.FieldRenderingControl.ToString()) 
    { 
     case "Microsoft.SharePoint.WebControls.TextField": 
      return CreateTextFieldControl(field, list, item, mode); 
    } 
} 

#region Create SharePoint Controls 
private static Control CreateTextFieldControl(SPField field, SPList list, SPListItem item, SPControlMode mode) 
{ 
    TextField tf = new TextField(); 
    //tf.EnableViewState=false; 
    tf.ListId = list.ID; 
    if (item != null) 
    { 
     tf.ItemId = item.ID; 
    } 
    tf.FieldName = field.Title; 
    tf.ID = "Field_" + field.Id; 
    //tf.CssClass = "spsControl"; 
    tf.ControlMode = mode; 
    //check if the field has a default value 
    if (field.DefaultValue != "null" && field.DefaultValue != null) 
    { 
     tf.Text = field.DefaultValue.ToString(); 
    } 
    try 
    { 
     RequiredFieldValidator cntrlValidator = ((RequiredFieldValidator)tf.Controls[0].Controls[3]); 
    } 
    catch (Exception ex) 
    { 
    } 

    return tf; 
} 

모든 셰어 컨트롤이 작동하고 TF가 올바르게 반환됩니다,하지만 난 현재 사이트 또는 현재 웹 에 아닙니다 때이 예외가 발생했습니다 : InvalidArgumentException를 컨트롤에. 이러한 컨트롤이 현재 사이트 나 웹 외부에서 작동하지 않는다고 생각합니다. asp.net 컨트롤을 사용해야합니다. 그것은 맞습니까? 아니면 다른 해결책이 있습니까? 미리 감사드립니다 ...

+0

에 맞게 코드를 포맷하고 질문 자체로 옮길 수 있습니까? 근본적으로 spcontext를 가짜로 만들고 다른 sitecollection을로드해야합니다. –

0

가짜 Spcontext가 문제의 해결책입니다. Google, 도움이 될 것입니다.

+0

도움이되었습니다. 고마워 – Manale

관련 문제