2017-05-22 8 views
-2

LINK Extract Embedded Image Object in RTF 97-2003 문서에서 잘 작동하고 동일한 코드가 2007/2010에 현재 작동하지 않는다면 아래 링크와 동일한 코드가 있습니다. 우리는 일반적으로 RTF를 OLE 객체로 검사하고 회사 규칙에 따라 변환을 거부하지만 Office-2007/2010 RTF로 작성된 텍스트가 "object"로 작성된 경우에도 코드가 거부됩니다. Office-2007에서 만든 RTF를 식별 할 수있는 솔루션이 있습니까?OLE 객체가 rtf 파일에 존재하는지 확인하는 방법

 using (StreamReader sr = new StreamReader(filePath)) 
        { 
         RtfReader reader = new RtfReader(sr); 
         IEnumerator<RtfObject> enumerator = reader.Read().GetEnumerator(); 
         while (enumerator.MoveNext()) 
         { 
          if (enumerator.Current.Text == "object") 
          { 
           hasOLEObjects = true; 
           break; 
          } 
         } 
        } 


    public RtfReader(TextReader reader) 
      { 
       if (reader == null) 
        throw new ArgumentNullException("reader"); 

       Reader = reader; 
      } 


public class RtfObject 
    { 
     public RtfObject(string text) 
     { 
      if (text == null) 
       throw new ArgumentNullException("text"); 

      Text = text.Trim(); 
     } 

     public string Text { get; private set; } 
    } 
+0

어떤 네임 스페이스/패키지가'RtfReader'를 가져 왔습니까? –

+0

해당 TextReader – rajesh

+1

'RtfReader'라는 내장 클래스가 없습니다. 이것은 자신의 프로젝트 형태의 클래스처럼 보입니다. 분명한 문제를 추측하는 것 외에는 게시하지 않은 코드를 도울 수 없습니다. 예를 들어, 요소 대신 해당 요소의 * 내용 *을 검사하는 이유는 무엇입니까? 'RtfReader'가 엘리먼트 타입을 노출하지 않습니까? 지금은 텍스트에'object'라는 단어가있는 문서를 거부하고 있습니다. 사용자가'Object'라는 제목을 가진 템플릿을 사용하기 시작하면 어떻게 될까요? –

답변

0

조건이 OLE 개체 (RtfReader.MoveToNextControlWord은 (열거, "objclass은"))

수 있음이 도움이된다면 사람

를 확인하는 경우에 나는 하나 더 추가 한
public static bool ValidateOLEObjects(string filePath) 
     { 
      bool hasOLEObjects = false; 
      using (StreamReader sr = new StreamReader(filePath)) 
      { 
       RtfReader reader = new RtfReader(sr); 
       IEnumerator<RtfObject> enumerator = reader.Read().GetEnumerator(); 
       while (enumerator.MoveNext()) 
       { 
        if (enumerator.Current.Text == "object") 
        { 
         if (RtfReader.MoveToNextControlWord(enumerator, "objclass")) 
         { 
          hasOLEObjects = true; 
          break; 

          } 
        } 
       } 

       return hasOLEObjects; 
      } 
     }