Exemple #1
0
        private async void downloadNote(String noteId)
        {
            if (client == null || client.Session == null)
            {
                statusTxt.Text = "You need to Sign In";
            }
            else
            {
                if (needToSave)
                {
                    statusTxt.Text = "Need to save file.";
                }
                try
                {
                    Stream downloadResult = await client.Download(noteId + "/content?return_ssl_resources=true");

                    // Get the stream with the downloaded file
                    var memoryStream = downloadResult as MemoryStream;

                    // Cursor is at the end of the stream so we need to rewind
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    // Read stream into a byte array
                    byte[] bytes    = new byte[1000];
                    int    numbytes = memoryStream.Read(bytes, 0, (int)memoryStream.Length);

                    // Prevent loading textbox from firing a text change event
                    notesEditor.TextChanged -= notesEditor_TextChanged;

                    // Load text into the TextBox decoding it as UTF8
                    System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                    notesEditor.Text = enc.GetString(bytes, 0, numbytes);

                    // Enable editing note content
                    notesEditor.IsReadOnly = false;

                    // Set Save status to false
                    needToSave = false;
                    deleteNoteBtn.IsEnabled = true;
                    saveBtn.IsEnabled       = false;
                    cancelBtn.IsEnabled     = false;

                    // Enable detecting changes
                    notesEditor.TextChanged += notesEditor_TextChanged;

                    statusTxt.Text = "Downloaded note (" + numbytes + " bytes)";
                }
                catch (LiveConnectException e)
                {
                    statusTxt.Text = e.Message;
                }
            }
        }