Create Folders and file in side Universal Window App - c#

I am programming on Universal Windows Platform and want to create a folder in the given path URL but without using ApplicationData.Current.LocalFolder because it returns the path C: but the given path varies. Please advise.

We can not create a folder and a file from an arbitrary location on disk in a UWP App.
Apps can access certain file system locations by default. Apps can also access additional locations through the file picker, or by declaring capabilities.
For more info, please refer the File access permissions.
If you want to create a folder and a file to the Music, Pictures, and Videos libraries, we can declare capabilities in the app manifest (see App capability declarations). For more info, please refer Files and folders in the Music, Pictures, and Videos libraries.
We can also use the User’s Downloads folder. By default, your app can only access files and folders in the user's Downloads folder that your app created.
For the other Folders and files, we can call a file picker to let the user pick files and folders for the app to access (see Open files and folders with a picker).

Related

How to include externel user files into UWP side-loading package?

Say I use some .json files to descript some object data which effect to the program's behavior, I hope to use these files in the following scenarios
The default values, for this purpose, I need a set of files follows with the application to be packed and installed.
I wish it could be edited by human manually. (Because something have no interface to be modify on UI)
Both user and the program need to kwnow the location the files will be placed after installation.
In debugging stage, I could put these files in the user\AppData\Local.. folder and I know how to access them, but I don't know how to put files into the package and will them generated to anywhere after install?
Thank you for any suggestion.
ps.
I use the "Blank App (WinUI 3 in UWP)" template to create my
application.
I'm new in UWP and WinUI, I used to write traditional Windows Form programs.
How to include externel user files into UWP side-loading package?
You could place the json file into app's project and set the file property as Content, then it will deploy into installtion folder after package install. and please note the json file is readonly in the installtion folder.
so you could call CopyAsync method copy the file to the destination folder that app's local folder with full permission.
For more details about file access permissions please refer this document.

Create app with data already present on install

I'm currently programming an app that need to access to some Excel files.
So what I need is to create a folder in the app files with these Excel files in it but I want that folder to be created at the app install, so they would be accessible for every device that install the app.
The files also need to be modifiable in the future by the user.
The problem is that I don't know how to do it right. Should I just create a new folder in the Solution Explorer and put the Excel files in it ? Should I create the folder programmatically and force the user to put them manually in that folder ?
I don't really know how to do it so that the application will not be too complicated to be modified by the user.
EDIT : Also, if I put the files in the Assets, will the user be able to change them later ?
So what I need is to create a folder in the app files with these Excel files in it but I want that folder to be created at the app install, so they would be accessible for every device that install the app. The files also need to be modifiable in the future by the user.
For your requirement, you could use ApplicationData.LocalFolder to store Excel files, LocalFolder has full access permission. LocalFolder exists in the app's sandbox path and will be created after the app is installed.
Also, if I put the files in the Assets, will the user be able to change them later ?
Assets folder exists in Windows.ApplicationModel.Package.Current.InstalledLocation and it is read only that often use to store some static resource. You can't modify the file at run time.
For more details about file access permissions please refer this document.
Forget the installer. It is deprecated and the new apps on Windows are installed over the store.
If you want to copy some files (Excel templates), you have to put them in your resources. At startup you can check if there is a folder in your App-Data folder with your files, if you don't find them, you can copy it from your resources. So even if the file is deleted, your app can copy them in the next start.
If you use Windows Forms with .NET, you can check this page:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.localuserappdatapath?view=netframework-4.8
If you are writing an UWP-app, check this page:
https://learn.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data

Create and Delete Folder. Move the file to folder and move the file to outside of the folder

have a gridview that contains files and folders. I would like if the user clicked the "add folder", then it will create a folder with the name of the folder the user wants.
Users can also move the files into the desired folder by selecting the "move to folder" to folder the user wants (displayed menu folder names available and also menu canceled). Users can also move files that are in the folder, outside of the folder.
Users can also delete folders available (if no files available in the folder).
How to apply?
Is there any reference or sample to it?
For your required features, uwp has StorageFile and StorageFolder relevant APIs can implement.
For example, create folder we can use StorageFolder.CreateFolderAsync method, delete folder we can use StorageFolder.DeleteAsync method, and for moving file we can copy the file to the destination folder firstly by StorageFile.CopyAsync method and then delete the original file by StorageFile.DeleteAsync method.
More details please reference this official document and the official sample File Access.
Pay attention that in uwp files have limited access permission. By the default the app can only access the application install directory and data locations. Additional locations require special capabilities. More details about file access permission please reference this document.

How to access a folder in c# in application files which is created after publishing application using relative path?

I am creating a application where I need to access images from a image folder in application files which I will add later after publishing the application. But the thing is when I access my application data path it is .../AppData/Temp...
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
So what is the way to access the data in Application Files in .exe directory.
My base directory is in Temp. But I want to access the one from where I executed the .exe
See more How can I get the application's path in a .NET console application?
Sulotion:
Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location,#"/Images/logo.png");
I hope this helps you.

saving file in Assets folder in Windows 8 App

I am developing an App for Windows Store.
I have to save a recorded media as "file1.mp3" into the Assets folder without opening the save file prompt. I used the following code
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFileAsync(#"Assets\file1.mp3",Windows.Storage.CreationCollisionOption.ReplaceExisting);
However the system returns an "access denied" error. The file has to be saved in the Assets directory only and I do not want to use FileSavePicker. Please Help.
Thanks
Your package folder is read-only. Use your app data folders from Windows.Storage.ApplicationData.Current instead, wherein you'll find a LocalFolder and TemporaryFolder (also RoamingFolder but an mp3 would exceed the 100KB roaming limit). Then you can use either folder's CreateFileAsync.

Categories

Resources