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.