Firstly, sorry this beginner's question.
But i'm really don't know the concept of path
I want to save my image files on uwp's resources History folder that i created.
So that I can open that images or save them.
But i can't find a way how to access my own folder
I tried appdata.localfolder but that's not for me
Anyone know the solution to this?
Thank you for reading this !
The images in the History folder are part of the program and are built to the package's installation directory. You can take it the equivalent of the C:\Program Files\Your App folder, the files are read-only.
To access the files from the History folder, use
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///History/yourfile.jpg"));
AppData.LocalFolder on the other hand, is your app's data folder, that is where the app data files - files that generated by the app - are located, and you can save app data there.
You can refer to this for how to write to the app data folder.
Related
I've got a csv file stored in my solutions's assets folder. Every now and then a copy of the csv is updated on a shared drive. Is there a way to copy this file and replace the version in the assets folder automatically. (I'd just reference the shared file rather than an internal one but occasionally the network plays up. I guess I could just have it copy to a location locally but I'd rather do it this way if possible)
I've added something to copy the file over on app launch but don't have permissions. I've guessing that assets are read only during runtime? Is there a way around this?
This is the line of code that triggers the error. File.Copy(sharedPath, assetPath, true);
Error: Access to the path 'C:\Users...AppX\Assets\file.csv' is
denied.
Update an assets file (C#/UWP)
During checking the path, and it looks a apps installation folder, unfortunately, the installation folder is read-only, we can't write data into. we suggest you use app' local folder that with full permission.
For your scenario, you could copy the csv file where in the assets folder to app's local folder when app fist launch. when you want to update csv file you just need to replace local folder's csv with shared drive.
For more detail please refer this document.
I want to acess a .txt file, which I stored in the resources folder of my project, there where all the imported pictures are stored as well.
I want to use something like a relative path, since every user would have safed his programm somewehere else on his Pc, but there is always the resources folder at the same place, compared to the programm folder.
I tried to used this: displayText = System.IO.File.ReadAllText("Resources\\startmessages.txt"); but this isn't working.
I get this error message: System.IO.DirectoryNotFoundException:, it lists the unrelative path to the .txt there as well, so I don't get, why it cant read it.
Thanks for your Help.
What #ChetanRanpariya is trying to tell you is, that your programm is built in another folder than your folder Resources is sitting to. So you have explictly tell your file Resources\startmessages.txt to copy itself on build process, so it get copied to said another folder. Assuming that you are using Visual Studio, you have to right click on your file and set Copy To Output Directory to true. Its relative folder path (Resources\) will be taken over. You find your build folder somewhere in your bin folder depending on configuration and framework. :)
Current Path where your executable is
Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).FullName
Path to Solution
If you are using Visual Studio and need to access the folders in the solution directory, you can use .Parent method,
Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName
Use of Path.Combine
and once you have the location of your Resource folder, use Path.Combine to get the location to read files / content etc
Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName, "Resources\\startMessages.txt")
Well, I don't if I asked well this question because I have the next problem:
Code
As you can see here, in one of my many WindowsForms I read a specific file.exe as well with file.txt with their own directions, when I run this (Debug) it works perfectly fine because the Folder that storage those files are inside of \WindowsFormsApp1\WindowsFormsApp1\bin\Debug.
Maybe the worst idea, because I want to 'release' this project, once I do this, I get a lot of errors of missing files (Because of the folder) except with certain images that I imported to Resources.rex.
Any suggestion?, like how can I keep all those .txt files with the .exe files, and still reading and running them when I use 'release' from Visual Studio
EDIT:
Error
This is the Release version, some images are intact but when I try to read the .txt files or Run the .exe files I get this message
If you have created exe for that, best suggestion that store those files in C drive as there will be no such folder of debug or release when you export exe. And even instance will be running from another folder which may be not same as you have provided folder path in your application. You should provide a path of folder, if that path is not present then create the folder as below.
string folderPath = "C:\\YourFolderPath\\";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
This may solve the issue but it is not still correct way to do.
I am trying to access the help file that I made in the resource of the visual studio. The way that I access it is using:
Help.ShowHelp(this, "D:\TEs\TEs\Resources\Manual.chm");
This doesn't work when I create an executable file and try it on another computer because there is no file in the TEs directory.
What is the best way for my programme to always call the help file from the resources?
Place your .chm in the same folder as the executable and use a relative path to access it.
Note that your application's working folder may change during execution, so you'll probably want to use a folder relative to the location of Assembly.GetEntryAssembly().
I am trying to write a small application, whose only purpose is to copy some folders and .cs source files into a user specified Directory, I can do it easy enough by simply having the application look for the files and folders in its own install directory then copy them to thier destination Directory, but I was wondering if its possible to Embed the Folders and Files into the Application, so that when you run the application it creates or copies the folders and files from the exe app directly to the install directory, rather than searching for them in the apps install directory then copying them over. Basically Im trying to only have a single exe file rather than having an exe file and a bunch of folders and files along side it.
Is this possible to do with just a Windows Form App without using an actual Installer Class?
Yes. Embed the files into the application executable as embedded resources. Then when your application runs, access the embedded files and write them to disk in the desired directory structure.
Here is an example of how to embed and access embedded resources from your application assembly.
http://support.microsoft.com/kb/319292
Sure you can, use the BuildAction property as Content or Resource.
Depending on the number and structure of files/folders, you may also consider embedding one zip file and extracting it with sharpziplib or some such.