سؤال

أرغب في حفظ محتوى RichTextBox إلى Varbinary (= صفيف البايت) بتنسيق XamlPackage. أحتاج إلى تقديم نصيحة تقنية حول كيفية ذلك.

أحتاج فعلاً إلى معرفة كيفية التحويل بين 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
هل كانت مفيدة؟

المحلول

لا يمكنني العثور على مثالي الكامل في الوقت الحالي ، ولكن يمكنك استخدام XamlReader و XamlWriter للحصول على المستند من وإلى سلسلة. من هناك ، يمكنك استخدام Unicodeencoding أو Asciiencoding أو أي تشفير تريد الحصول عليه من وخارج البايت.

مثالي الأقصر على تعيين المستند من سلسلة ... DeCreader هو قارئ مستند التدفق الخاص بي

        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;
            }
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top