2009-10-27 4 views
0

RichTextBox의 내용을 XamlPackage 형식의 varbinary (= 바이트 배열)에 저장하려고합니다. 방법에 대한 기술적 인 조언이 필요합니다.RichTextBox 내용을 SQL varbinary (바이트 배열) 열에 어떻게 저장합니까?

저는 실제로 FlowDocument와 바이트 배열 사이의 변환 방법을 알아야합니다.

varbinary로 저장하는 것이 좋습니다? 아니면 좋지 않은 아이디어입니까?


업데이트

코드 :

///Load 
byte[] document = GetDocumentFromDataBase(); 
RickTextBox tb = new RickTextBox(); 
TextRange tr = new TextRange(tb.Document.ContentStart, tb.Document.ContentEnd) 
tr.Load(--------------------------) //Load from the byte array. 


///Save 
int maxAllowed = 1024; 
byte[] document; 
RichTextBox tb = new RichTextBox(); 
//User entered text and designs in the rich text 
TextRange tr = new TextRange(tb.Document.ContentStart, tb.Document.ContentEnd) 
tr.Save(--------------------------) //Save to byte array 
if (document.Length > maxAllowed) 
{ 
    MessageBox.Show((document.Length - maxAllowed) + " Exceeding limit."); 
    return; 
} 
SaveToDataBase(); 
TextRange 

답변

0

내가 지금 내 전체 예제를 찾을 수 없습니다,하지만 당신은로와에서 문서를 얻을 수 XamlReader 및 XamlWriter를 사용할 수 있습니다 문자열. 거기에서 유니 코드 인코딩, AsciiEncoding 또는 원하는 모든 인코더를 바이트 단위로 가져 오거나 바이트 단위로 가져올 수 있습니다.

문자열에서 문서 설정에 대한 나의 짧은 예 ... docReader 내 흐름 문서 리더

 private void SetDetails(string detailsString) 
    { 
     if (docReader == null) 
      return; 
     if (String.IsNullOrEmpty(detailsString)) 
     { 
      this.docReader.Document = null; 
      return; 
     } 
     using (
     StringReader stringReader = new StringReader(detailsString)) 
     { 
      using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stringReader)) 
      { 
       this.docReader.Document = XamlReader.Load(reader) as FlowDocument; 
      } 
     } 
    } 
+0

입니다 심지어 VARBINARY로 저장하는 것이 좋습니다, 또는이 나쁜 생각입니까? – Shimmy

+1

끔찍한 생각은 아닌 것 같아요. 그러나 이것들이 커질 수 있다는 점을 명심하십시오. varbinary (max)를 지원하는 DB에서 사용하지 않으면, 대신 BLOB 데이터 유형을 고려해야합니다. . –

+0

저장소에 대해 이야기하는 것이 아니라 성능, 즉 바이트 배열의 압축 풀기에 대해 묻습니다. 블롭에 대해서 : 1) 큰 문서를 사용하지 않을 것입니다. 2)이 프로젝트에서 저는 2005를 사용합니다. – Shimmy