Ниже находится код, чтобы открыть аннотации к/из файламагазин Аннотация в базе данных
Как бы загрузить и сохранить аннотации к базе данных?
База данных MS SQL Server, и я знаю, как читать и писать текст, xml и двоичный файл. Просто нужно знать, какой поток использовать и как его использовать.
Я предпочитаю не держать соединение с базой данных открытой. Что-то вроде чтения, а затем держите в памяти, а затем пишите?
using System.Windows.Annotations;
private FileStream streamAnno;
private void Page_Loaded(object sender, RoutedEventArgs e)
{
/// Creates an annotation service based on
/// a FlowDocumentReader control.
AnnotationService service = AnnotationService.GetService(FlowDocumentPageViewer1);
/// Checks if the service has not been instantiated.
if (service == null)
{
/// Instantiates a FileStream object.
streamAnno = new FileStream("tip100annotations.xml", FileMode.OpenOrCreate);
/// Instantiates the annotation service.
service = new AnnotationService(FlowDocumentPageViewer1);
/// Creates an annotation store using the derived
/// XmlStreamStore object and the FileStream object.
System.Windows.Annotations.Storage.AnnotationStore store = new System.Windows.Annotations.Storage.XmlStreamStore(streamAnno);
/// Sets the AutoFlush property to true to ensure
/// that every annotation is flushed to the store automatically.
store.AutoFlush = true;
/// Enables the annotation service.
service.Enable(store);
}
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
/// Tries to get the annotation service.
AnnotationService service = AnnotationService.GetService(FlowDocumentPageViewer1);
/// If the annotation service is valid and is enabled
if (service != null && service.IsEnabled)
{
/// Disables the service.
service.Disable();
/// Closes the stream
///
if (streamAnno != null)
{
streamAnno.Close();
}
}
}