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.
Related
I need to open a kmz file from the mobile app in order to see it in google earth, So i saved the kmz file in the StreamingAssets and i copy it to the persistentDataPath, Also the file is unable to open when i copy it to this folder.
Im calling it with this:
Application.OpenURL("file://"+Application.persistentDataPath + "/CR.kmz");
I already granted the file permissions.
I dont know how to open files from the storage with code. Help.
I'm trying to save a file without a filepicker under my desktop or somewhere else, but I always get the error "Access to path [...] is denied"
This is my code:
private async void SaveFile(string Path)
{
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(Path);
StorageFile sampleFile = await folder.CreateFileAsync("sample.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
}
I tried the same code but with the Localfoder and it worked.
Is there any way to get access to the path without a filepicker?
Using FilePicker gets permission from the user to access file locations. File system access is a restricted capability in UWP. You can enable Broad Filesystem Access in your package manifest to get this permission when the app is installed. It's not recommended for apps published to the Microsoft Store, because it makes it less likely for you app to be approved. See the App capability declarations documentation.
Alternatively, you could run your app from a folder that contains the desktop in one of its subfolders by using the AppExecutionAlias extension mention under Accessing additional locations in File Access Permissions. Underneath that section there is also an explanation of Broad Filesystem Access as well.
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
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).
In my win forms C# app, I am exporting my images to pdf and word. Before export, images need to be saved as bitmap. Did it like this:
// code
bitmap.Save("Image.jpeg", ImageFormat.Jpeg);
bitmap.Dispose();
Now the code for word and pdf export read this file normally from saved location. Howewer, while I was testing my desktop app, code "Image.jpeg"saves image to bin directory.
When I made installer using InstallShield and installed my program, this option works but it save my image to desktop. I don't really want that.
Managed to send it to ApplicationData directory but don't want that either...
string imageSaved = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Image.jpeg");
bitmap.Save(imageSaved, ImageFormat.Jpeg);
bitmap.Dispose();
How to navigate my file to installation directory?
Simply use Application.StartupPath
Gets the path for the executable file that started the application,
not including the executable name.
The path for the executable file that started the application. This
path will be different depending on whether the Windows Forms
application is deployed using ClickOnce. ClickOnce applications are
stored in a per-user application cache in the C:\Documents and
Settings\username directory.
For example you can use it this way:
string imageSaved = Path.Combine(Application.StartupPath, "Image.jpeg");
bitmap.Save(imageSaved, ImageFormat.Jpeg);
For ClickOnce applications, you can use ApplicationDeployment.CurrentDeployment.DataDirectory, for more information, see Accessing Local and Remote Data in ClickOnce Applications