0

I want to create a folder directory and in that folder, I want to save the image and get the response. but when I check manually using file explorer the folder is not showing.

//take picture code

string DirName = "Sample";
string ImgName = "image.jpg";
string basepath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);

 takePhoto.Clicked += async (sender, args) =>
        {

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("No Camera", ":( No camera available.", "OK");
                return;
            }

            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
            });

            byte[] imageArray = null;
            if (file != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    var stream = file.GetStream();
                    stream.CopyTo(ms);
                    imageArray = ms.ToArray();
                }
            }
            Stream data = new MemoryStream(imageArray);

            if (file == null)
                return;
            
            filePath = file.Path;
            paths.Enqueue(filePath);
            var result = await CrossEDFSTemplate.Current.SaveFile(basepath, DirName,ImgName, filePath);
            await DisplayAlert("Succesful", result.ToString(), "ok");

//Directory create code

    public async Task<SaveFileResponse> SaveFile(string FolderBasePath, string FolderName, string 
    FileName, string FileFullPath = null, Stream data = null)
    {
        SaveCompletionSource = new TaskCompletionSource<SaveFileResponse>();
        if (FolderBasePath != null && FolderName != null)
        {
            var directoryPath = Path.Combine(FolderBasePath, FolderName);
            string NemFilePath = Path.Combine(directoryPath, FileName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            if (FileFullPath != null)
            {
                var imageData = File.ReadAllBytes(FileFullPath);

                File.WriteAllBytes(NemFilePath, imageData);

            }
            else if (data != null)
            {
                byte[] bArray = new byte[data.Length];
                using (FileStream fs = new FileStream(NemFilePath, FileMode.OpenOrCreate))
                {
                    using (data)
                    {
                        data.Read(bArray, 0, (int)data.Length);
                    }
                    int length = bArray.Length;
                    fs.Write(bArray, 0, length);
                }
            }
            else
            {
                var ResponseSaved = new SaveFileResponse("There are no items to Save", null, FileName);
                SaveFileError(this, ResponseSaved);
                SaveCompletionSource.TrySetResult(ResponseSaved);
            }
        }
        else
        {
            return await SaveCompletionSource.Task;
        }
        return await SaveCompletionSource.Task;
    }

according to this code, the directory is creating but when I manually checking that folder using file explorer the folder is not showing.

Sunny
  • 23
  • 5
  • 1
    you cannot just browse the Android file system using Windows File Explorer. You need to use the adb tools – Jason May 06 '21 at 11:00

1 Answers1

0

The path Environment.SpecialFolder.MyPictures you used to save the file is internal storage.

In Internal Storage, you couldn't see the files without root permission.

But you could use the code to check the file exist or not in the internal storage.

 if (File.Exists(filepath))
    {

    }

If you want to view it, you could use adb tool. Please check the way in link.

How to write the username in a local txt file when login success and check on file for next login?

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17