2011-04-18 3 views
2

Sharepoint 라이브러리에서 문서 목록을 가져옵니다. 내 임무는 그가 docx 파일을 열 수 있도록 사용자에게 그 목록에있는 첫 번째 문서를 검색하는 것이라고 가정 해 봅시다. 어떻게해야합니까?Sharepoint Document 라이브러리에서 사용자에게 문서를 반환하려면 어떻게해야합니까?

더 복잡한 것은 SharePoint 서버가 다른 도메인에 있다는 것입니다. 내가 작업하고있는 웹 프로젝트는 고객에게 문서를 보여 주지만 셰어 포인트 서버에 대한 직접 액세스는 노출시키지 않습니다.

ClientContext clientContext = new ClientContext(URL); 
    List list = clientContext.Web.Lists.GetByTitle("My Documents"); 

    CamlQuery camlQuery = new CamlQuery(); 
    camlQuery.ViewXml = XML; 
    ListItemCollection listItems = list.GetItems(camlQuery); 
    clientContext.Load(
     listItems, 
     items => items.Include(item => item["FileRef"])); 

    clientContext.ExecuteQuery(); 

    // return this file to the user 
    // listItems[0]; 

답변

1

솔루션 요약은 다음과 같습니다. 앵커 태그를 생성 할 때 문서에 값이 있어야하는 FileRef 필드의 정보를 포함합니다. 이 필드는 나중에 사용할 참조 필드입니다.

당신은 당신이 호출 할 때 참조를 사용합니다

 FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, reference); 

     Stream stream = fileInformation.Stream; 
     if (stream != null) 
     { 
      documentName = Path.GetFileName(reference); 

      return new FileStreamResult(stream, "unknown") 
      { 
       FileDownloadName = documentName 
      }; 
     } 
3

당신은 사용자가 단순히 항목에 대한 전체 경로와 링크를 클릭 할 수 있도록이 쿼리의 결과에 따라 "A"요소를 만들 수 있습니다 (이 SharePoint 목록의 렌더링 대략적으로 일반)입니다.