Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async void ButtonSave_Click(object sender, RoutedEventArgs e)
- {
- if (TextBoxName.Text.Length <= 2)
- {
- MessageDialog msg = new MessageDialog("Names don't allow 2 or less characters", "Information");
- await msg.ShowAsync();
- return;
- }
- //aqui introduce los datos de los textbox
- //instanciamos la clase Activity
- Activity Activity = new Activity();
- Activity.Name = TextBoxName.Text;
- Activity.Participant = TextBoxParticipant.Text;
- //Activity.Map =
- Activity.Description = TextBoxDescription.Text;
- Activity.Type = TextBoxType.Text;
- Activity.Price = TextBoxPrice.Text;
- Activity.Difficulty = TextBoxDifficulty.Text;
- Activity.Comments = TextBoxComment.Text;
- //serializar el objeto antes de salvarlo con el nombre que queremos
- // aqui ya hacemos el proceso de salvado de datos
- FileSavePicker fileSavePicker = new FileSavePicker();
- //FileSavePicker savePicker = new FileSavePicker();
- fileSavePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
- // Dropdown of file types the user can save the file as
- fileSavePicker.FileTypeChoices.Add("Activities Documents", new List<string>() { ".act" });
- fileSavePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
- // Default extension if the user does not select a choice explicitly from the dropdown
- fileSavePicker.DefaultFileExtension = ".docx";
- // Default file name if the user does not type one in or select a file to replace
- fileSavePicker.SuggestedFileName = "New Document";
- StorageFile savedFile = await fileSavePicker.PickSaveFileAsync();
- string savedFilePath = savedFile.Path;
- string savedFileName = savedFile.Name;
- // Get the output stream for the SessionState file.
- savedFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(savedFileName, CreationCollisionOption.ReplaceExisting);
- IRandomAccessStream raStream = await savedFile.OpenAsync(FileAccessMode.ReadWrite);
- //StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("samplefile.dat", CreationCollisionOption.ReplaceExisting);
- //IRandomAccessStream raStream = await file.OpenAsync(FileAccessMode.ReadWrite);
- IOutputStream outStream = raStream.GetOutputStreamAt(0);
- // Serializar objeto a fichero
- //DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
- DataContractSerializer serializar = new DataContractSerializer(typeof(Dictionary<string, object>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
- try
- {
- serializar.WriteObject(outStream.AsStreamForWrite(), Activity);
- }
- catch (Exception ex)
- {
- MessageDialog msg = new MessageDialog(ex.Message);
- }
- await outStream.FlushAsync();
- } // fin metodo ButtonSave_Click
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement