Exemplo n.º 1
0
        private async void SearchSavedFolders(string searchString = "")
        {
            List <DocumentFolder> lstDocFolders        = new List <DocumentFolder>();
            string           RootFolderExternalStorage = StorageUtilities.GetInstance().GetAppExternalStorageFolderName();
            PermissionStatus readPermission            = await PermissionUtilities.GetInstance().RequestExtrenalStorageReadPermission();

            if (Directory.Exists(RootFolderExternalStorage) && readPermission == PermissionStatus.Granted)
            {
                string[] folderNamesList = Directory.GetDirectories(RootFolderExternalStorage);
                foreach (string folderName in folderNamesList)
                {
                    DocumentFolder docFolder = new DocumentFolder();
                    DirectoryInfo  dir       = new DirectoryInfo(folderName);
                    docFolder.FolderName = dir.Name;
                    docFolder.FolderPath = dir.FullName;
                    lstDocFolders.Add(docFolder);
                }
                //--For Search:
                lstDocFolders = lstDocFolders.FindAll(d => d.FolderName.ToLower().Contains(searchString.ToLower()));

                _lstFolders             = new ObservableCollection <DocumentFolder>(lstDocFolders);
                lstFolders.ItemsSource  = _lstFolders;
                lstFolders.SelectedItem = null;
            }
        }
Exemplo n.º 2
0
        private async void btnSave_Clicked(object sender, EventArgs e)
        {
            try
            {
                PermissionStatus status = await PermissionUtilities.GetInstance().RequestExtrenalStorageWritePermission();

                if (status == PermissionStatus.Granted)
                {
                    string FolderNameInput = string.Empty;
                    if (string.IsNullOrEmpty(_ParentFolderName))    //Direct camera on from Landing Page
                    {
                        FolderNameInput = await DisplayPromptAsync("Name", "What Document is this?",
                                                                   initialValue : "SampleDoc", keyboard : Keyboard.Default);

                        if (string.IsNullOrEmpty(FolderNameInput))
                        {
                            FolderNameInput = DateTime.Now.ToFileTime().ToString();
                        }

                        _ParentFolderName = FolderNameInput;
                    }


                    string PublicExternalFolderPath = StorageUtilities.GetInstance().GetAppExternalStorageFolderName();
                    //1st time case
                    if (!Directory.Exists(PublicExternalFolderPath))
                    {
                        Directory.CreateDirectory(PublicExternalFolderPath);
                    }

                    string SaveDirectory = Path.Combine(PublicExternalFolderPath, _ParentFolderName);
                    if (!Directory.Exists(SaveDirectory))
                    {
                        Directory.CreateDirectory(SaveDirectory);
                    }

                    string saveFileName = DateTime.Now.ToFileTime().ToString();
                    string SaveFilePath = Path.Combine(SaveDirectory, saveFileName + ".jpg");
                    File.Copy(_EditFile, SaveFilePath, true);

                    GC.Collect();
                    await Navigation.PushAsync(new DocumentLandingPage());
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
        }