I am saving log files on a Raspberry Pi using this method to get the save path:
private static string GetFullFilePath(ISettingsReader settingsReader)
{
StorageFolder appLocalFolder = ApplicationData.Current.LocalFolder;
var logFilPath = appLocalFolder.Path + settingsReader.LogFileName;
return logFilPath;
}
The files are saved at this location on the RPi:
c$\Data\Users\DefaultAccount\AppData\Local\Packages\MyApp_ktn1kqb2ndh66\LocalState\Logs
If I open Device Portal - File Explorer I see a slightly different name for my app: User Folders\LocalAppData\MyApp_1.0.0.0_arm_ktn1kqb2ndh66
There are no files under that link.
If I search for the folder name on the RPi I can find it under c$\Data\ProgramData\Microsoft\Windows\AppRepository\Packages
Where do I have to save the files so that they are available on the Device Portal?
Related
I am running a .net Core 3.1 application on a Debian 10 Server. The application has to copy a given Windows source Directory to a Windows network drive. When copying the files and Directories, it has to set the Destination Files and Directories acl to the Source acl.
I tried doing this using Mono.Unix. To access the Windows Network drive on Linux, I mounted to a Diretory in /media.
// get Source Directories Info
var unixSrcDirInfo = new Mono.Unix.UnixDirectoryInfo(dir.FullName);
//get Destination Directory info
var unixDestDirInfo = new Mono.Unix.UnixDirectoryInfo(destinationDir);
//set Destination Directory File Permissions to Source Directory File Permission
unixDestDirInfo.FileAccessPermissions = unixSrcDirInfo.FileAccessPermissions;
unixDestDirInfo.Refresh();
Does somebody have an Idea how to copy the ACL of a file on a Linux Machine?
I tried using System.IO.FileSystem.AccessControl, but that's not allowed on Linux. I tried using Mono.Unix, but it doesn't copy the permissions.
I just want to set the Destination Directorys ACL to the Source Directorys ACL.
Environment: Microsoft.Data.Sqlite.Core, SQLitePCLRaw.bundle_winsqlite3 2.0.1, Windows-10, VS2019- ver16.3.6
Following code works in my UWP app to create a a file in Downloads folder in Windows 10, and also can write to that file. But, as shown in the second code block below, when I do the same by creating an SQLite file, say, sqliteSample.db in the Downloads folder and then try to open that db it gives me the error shown below:
Following code snippet works for creating and writing to a file in Downloads folder:
StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("sample.txt");
Windows.Storage.Pickers.FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads
};
folderPicker.FileTypeFilter.Add(".txt");
StorageFolder oPickedFolder = await folderPicker.PickSingleFolderAsync();
if (oPickedFolder != null)
{
//Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", oPickedFolder);
string sSQLDbPath = Path.Combine(oPickedFolder.Path, "sample.txt");
Windows.Storage.StorageFile sampleFile = await oPickedFolder.GetFileAsync("sample.txt");
await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Swift as a shadow");
}
Following code snippet successfully creates sqliteSample.db file in Downloads folder, but gives error shown below when trying to open it:
Remarks: Below error occurs at line db.Open(); of the following code. I've verified in the debug mode in VS2019 that the variable sSQLDbPath has the correct path and when I manually copy/paste that path to the Windows explorer, I can see the sqliteSample.db file in the same subfolder of the Downloads folder that also has the sample.txt file created from the above code and that works without error.
SQLite Error 14: 'unable to open database file'.
StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("sqliteSample.db");
Windows.Storage.Pickers.FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads
};
folderPicker.FileTypeFilter.Add(".db");
StorageFolder oPickedFolder = await folderPicker.PickSingleFolderAsync();
if (oPickedFolder != null)
{
//Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", oPickedFolder);
string sSQLDbPath = Path.Combine(oPickedFolder.Path, "sqliteSample.db");
using (SqliteConnection db = new SqliteConnection($"Filename={sSQLDbPath}"))
{
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
"Text_Entry NVARCHAR(2048) NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
}
}
From File and folder permissions in the Downloads folder:
The user can give another app access to your
file by selecting the file from the file picker. Your app can also use
the file picker to get access to the files in the Downloads folder
that it didn't create.
Capabilities are not needed to create or access files in the Downloads
folder.
NOTE: This post did not help either.
Short story: SQLite can't see the downloads folder. It can only write to databases in the app's ApplicationData folders.
Longer explanation: Your app has full access only to a few locations (i.e. read only to its install folder and read-write to its application data). Other locations (libraries granted via capabilities, picked files or folders, downloads directory) are granted access by the file broker. The app uses this access via functions that adhere to the UWP app security model such as the Windows.Storage classes (as demonstrated in your working code to create the database) and CreateFileFromApp.
SQLite's default implementation doesn't use any of these methods that use the brokered file access, so ApplicationData is the only read-write location that the default SQLite implementation can use without modification. You can grant the app access elsewhere (e.g. with the broadFileSystemAccess capability), but SQLite doesn't by default use the right API to make use of that access.
In theory you could modify SQLite to use these API (probably in a SQLite virtual file system), but I'm not aware of any actual implementations which have done so.
I want to play a local video inside my Xamarin.Android app but when I set the uri the Visual Studio output tells me that the app can't read the video.
My video is located in the "files" folder of my app:
com.myapp.myap
cache/
files/
videos_files/
video.mp4
Here's my code:
var videoview = this.FindViewById<VideoView>(Resource.Id.videoView);
var uri = Android.Net.Uri.Parse("android.resource://com.myapp.com/files/videos_files/video.mp4");
videoView.SetVideoURI(uri);
Using the android.resource://blahblahblah format is only used when your files are included in your Resources folder with Build Action AndroidResource.
If you want this, then you can move your video file into YourApp/Resources/Raw.
Then set up your path:
string videoPath = $"android.resource://com.myapp.com/{Resource.Raw.video}";
videoView.SetVideoPath(videoPath);
Im developing an Android app using the Xamarin platform and Im trying to create a folder on my local storage but I have had no success.
First I tried using the System.IO namespace through a FileManager class created by Xamarin Forms Labs. A snippet of the functions I was passing the path of "/storage/emulated/0/`".
public void CreateDirectory(string path)
{
this.isolatedStorageFile.CreateDirectory(path);
}
public Stream OpenFile(string path, FileMode mode, FileAccess access)
{
return (Stream)this.isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access);
}
This didn't work so I then opted to using PCLStorage a library for cross platform file operations. I tried this code.
IFolder rootFolder = FileSystem.Current.LocalStorage;
folder = await rootFolder.CreateFolderAsync("wakesocial",
CreationCollisionOption.OpenIfExists);
Didn't work. I navigated to the root of the internal storage and I didn't see the folder.
So the error doesn't seem to be occurring because of the libraries in use but something specific to Android. I have read and write to external storage in manifest. So the question is. Does an app have permission to create a file or folder at the root level of the storage device or does it have to create it at particular location such as in Android/data/packagename
string folderPath = Environment.ExternalStorageDirectory.AbsolutePath; //Android
public async Task PCLGenaratePdf(string folderPath )
{
IFolder rootFolder = await FileSystem.Current.GetFolderFromPathAsync(folderPath );
IFolder folder = await rootFolder.CreateFolderAsync("folder", CreationCollisionOption.OpenIfExists);
IFile file = await folder.CreateFileAsync("file.pdf", CreationCollisionOption.ReplaceExisting);
}
After lot of trying I solved this problem with this
string rootPath = Android.App.Application.Context.GetExternalFilesDir(null).ToString();
var filePathDir = Path.Combine(rootPath, "Folder");
if (!File.Exists(filePathDir))
{
Directory.CreateDirectory(filePathDir);
}
The folder created is reachable through adb # /sdcard/Android/Data/Folder or something like this, or in device memory # /Android/data/<< AppName >>/files/Folder
On Android, PCL Storage's LocalStorage folder corresponds to the "My Documents" Special Folder.
I'm not sure exactly what path you're trying to create a folder in, but if you know the path and want to use PCL Storage, you should be able to use FileSystem.Current.GetFolderFromPathAsync to get a PCL Storage IFolder corresponding to an existing folder.
i am trying to create a folder and copy some images into it using c# wpf application.
curName = txt_PoemName.Text;
// Specify a "currently active folder"
string activeDir = #"C:\Program Files\Default Company Name\Setup2\Poems";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, curName);
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
foreach(DictionaryEntry entry in curPoem){
string newFilePath = System.IO.Path.Combine(newPath, entry.Key.ToString() + Path.GetExtension(entry.Value.ToString()));
System.IO.File.Copy(entry.Value.ToString(), newFilePath, true);
}
i have successfully created the folder and images. and also i can access them via application. but i cant see them in the location on my local disk. when i restart the machine , then application also cant see them.how can i solve this?
Sounds like you have encountered UAC Data Redirection
http://blogs.windows.com/windows/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
You need to either force the application to run as an administrator.
How do I force my .NET application to run as administrator?
Or not save your data in a sensitive area. I would recommend saving in a subfolder of
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);