2012-07-12 3 views
5

클라이언트 개체 모델을 사용하여 Sharepoint 토론 게시판의 "ModifiedBy"필드를 업데이트하려고합니다. "Editor"및 "Author"필드를 변경하여 목록보기에 나타나는 "ModifiedBy"를 변경할 수 있습니다. 그러나 토론 게시물을 클릭하면 그곳에 나타나는 "ModifiedBy"필드 (그 위에 그림이있는)는 변경 사항을 반영하지 않습니다. 실험을 마친 후에, 이것을 교정하기 위해 바꿀 필요가있는 부분을 "MyEditor"라고 발견했습니다. 불행히도이 필드는 읽기 전용입니다.Sharepoint 클라이언트 개체 모델 설정 ModifiedBy 필드

아래 코드에서 필드의 읽기 전용 설정을 false로 변경하려고합니다. 첫 번째 블록의 맨 아래에있는 ExecuteQuery() 줄 다음에 Visual Studio 디버거의 MyEditor 필드를 보면 ReadOnlyField 값이 사실 false로 설정되었음을 알 수 있습니다.

 sharepointContext.Load(discussionList); 
     sharepointContext.ExecuteQuery(); 
     var fields = discussionList.Fields; 
     sharepointContext.Load(fields); 
     sharepointContext.ExecuteQuery(); 
     var field = fields.GetByInternalNameOrTitle("MyEditor"); 
     field.ReadOnlyField = false; 
     field.Update(); 
     sharepointContext.Load(field); 
     sharepointContext.ExecuteQuery(); 

위의 코드는 문제없이 실행됩니다.

 Invalid data has been used to update the list item. 
     The field you are trying to update may be read only. 

것이 있는지 확인하려면 다음

코드가 두 번째 블록의 하단에하는 executeQuery를()에 도달
 //...Code to initialize discussionItem... 
     discussionItem["MyEditor"] = 0; 
     discussionItem["Editor"] = 0; 
     discussionItem["Author"] = 0; 
     discussionItem["Body"] = "Testing"; 
     discussionItem["Title"] = "Hello Worlds"; 
     discussionItem.Update(); 
     sharepointContext.Load(discussionItem); 
     sharepointContext.ExecuteQuery(); 

, 그것은 다음과 같은 메시지와 함께 ServerException 예외 : 문제는이 다음 블록 함께 제공 MyEditor 필드가 예외를 던지게하는 원인이되었다는 것을 알기 위해 내가 설정 한 행을 주석 처리하고 코드를 다시 실행했습니다. 모든 것이 잘 작동했습니다. 나는 무엇이 잘못되었는지를 이해하지 못한다. 누군가 나를 도울 수 있는가?

+0

왜 (당신은 일반적인 목적을 위해 왜 필요하고) 당신이 가능해야한다고 생각합니까? 이러한 유형의 필드가 편집 가능할 것으로 기대하지 않습니다. 관리자가 아닌 계정을 사용하여이 필드를 변경하면 해당 버그가 저에게 느껴집니다. –

+0

필드의 ReadOnly 속성을 false로 설정하면이 필드에 쓸 수 있어야한다고 생각하기 때문에 가능해야한다고 생각합니다. 그렇지 않은 경우 ReadOnly 필드의 용도는 무엇입니까? 토론 게시판의 데이터를 다른 데이터베이스에서 Sharepoint로 마이그레이션 할 때 ModifiedBy 필드에 원래 게시 한 사람이 반영되도록하고 싶습니다 (현재로서는 내 이름 대신 표시됨). 내 계정에는 완전한 관리 권한이 있습니다. –

답변

1
ModifiedBy 및 CreadtedBy는이 같은 단지 저자 및 편집기 필드를 변경해야하는 저자 및 편집기에서 자동으로 계산

:

사람 이름으로 사용자를 찾을 필요가 경우
 using (var clientContext = new ClientContext(@"http://server")) 
     { 
      var web = clientContext.Web; 
      var lst = web.Lists.GetByTitle("Discus"); 

      var item = lst.GetItemById(2); 
      item["Author"] = 3; 
      item["Editor"] = 2; 
      item.Update(); 
      clientContext.ExecuteQuery();       

      Console.WriteLine("done"); 
     } 
+0

나는 이것을 알고있다. 항목을 추가 한 다음 GetItemById를 사용하여 항목을 검색하는 경우에만 작동합니다. 그것은 절대적으로 의미가 없습니다 (귀하의 잘못이 아닙니다). MyEditor 필드를 수정하여 처음으로 추가 할 수없는 이유를 알고 싶습니다. –

3

, 그것은 다음과 같이 진행됩니다

private static FieldUserValue GetUser(ClientContext clientContext, string userName) 
    { 
     var userValue = new FieldUserValue(); 
     var newUser = clientContext.Web.EnsureUser(userName); 
     clientContext.Load(newUser); 
     clientContext.ExecuteQuery(); 
     userValue.LookupId = newUser.Id; 
     return userValue; 
    } 

반환 값 이 항목을 통해 설정할 수 있습니다 [ "저자"]

관련 문제