Application Resource Path for iOS - c#

I have a question on how iOS create its folder, I have a function wherein it will generate a Pdf file and will be upload to list of attachment. In the screenshot the First Run section, this is the time the file is created F4CB04F6... is the folder where it is located.
However, when I close my application and run it again, and try to download the file, the detected path changed to FE438CE9...
Does it mean the application root is always creating a new folder?

This problem will just appear in the simulator. The path will change when you build or run the project every time. Accoridng to this case, the cause is the XCode will change the application's UUID every time.
But if you run it on the physical device, the path will be the same all the time. And you can use the relative path such as Path.Combine() to store or get the files.

Related

Update an assets file (C#/UWP)

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.

FileNotFoundException is occur while running Wpf application on 32bit machine

I created setup file using Inno setup.I have exe,dll and one xml file in my setup.
When I install on 64 bit machine it works fine means it take xml file from directory where exe is present.
But When I install same setup on 32 bit machine it take dll path but while accessing xml file it takes path of desktop where shortcut of exe is present and showing FileNotFoundException.
Thanks
Your application is most likely not specifying pathnames on the files it is trying to open, so it is expecting to find them in the current directory. Inno Setup by default does not set the "Start In" field on shortcuts its creates; this causes Windows to pick a directory itself, which usually won't be the directory containing your application.
In virtually all cases, this is something that should be corrected at the application level. Properly designed GUI applications should not expect to be started from a particular directory; they should always specify full pathnames on files they open. In Delphi or C++Builder, for example, it's possible to get the full pathname of the directory containing the application EXE by calling: ExtractFilePath(ParamStr(0)). To get the full path of a file named "File.txt" in the application directory, use: ExtractFilePath(ParamStr(0)) + 'File.txt'.
To get path of working directory of application while loading xml file in code.
string WorkingDir=System.AppDomain.CurrentDomain.BaseDirectory
XDocument temp_xdocument= XDocument.Load(WorkingDir+"file.xml");
It works for me.

Contents of bin folder after publishing .NET project to an MSI file - where will the image go?

I am working on a WinForms application which uses a flatbed scanner (in conjunction with PixTools library).
Currently when running in debug mode (unpublished), when the application code scans the image, it stores the image file .jpg in the bin folder of the project (C:...\Source\winapp\bin). My code then has to manually move this file using File.Move() to the directory where I want it to end up.
However I am thinking that when I publish the application to install on another machine, this bin folder won't exist. I am wondering where the application is likely to store the .jpg from the scanner in this case so I can write the code in advance. For instance, will the image appear somewhere in the installation folder which is selected when installing application the first time round?
Thanks for any advice/help
C
You can Create/Store your image file(.jpg) into your Debug/Release folder which is the path from where your Application exe runs.
The following code gives you the path from where your Application is running:
String ApplicationFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
The Above code returns the path similar to
SolutionFolder/ProjectFolder/bin/Debug(or)Release
So you can target your code to retrieve the image from the above location as it is avaialable even after deplyoing/Installing the Application on client PC.

Deploying c# application issues

I have a application with one folder which i added by right clicking the project, selecting add folder. Inside this folder i have xml files which are set to build action:content, copy to output directory: copy if newer (i have tried setting to embedded resource) As well as this i have a few text files and so on.
In my bin/debug output directory i have the exe, the folder with the xml, the stand alone .txt files and so on. My problem is, if i send the exe to my friend to try he always gets an exception thrown.
Say he puts the exe on the desktop, my programme at some point reads the filenames of the xml files in the folder. It uses the following code to do so
String[] filePaths = Directory.GetFiles(#"DataSources\");
I assume that because of this, when the exe runs from the desktop, it expect the folder of .xml files to be in the same place? I have the same type of exception when trying to read the .txt files too. What am i doing wrong here?
Thanks for your time
When reading from files using relative paths you get the one relative to the applications current directory. tip: In C# you can see what directory that is using Environment.CurrentDirectory.
So if you create a shortcut on your desktop, you need to make sure you right click the shortcut and set its "Start in"-folder to the directory of your application. That way its current directory will be set when its started and relative paths will be relative to that path and not the path of the shortcut.
If you actually moved the exe file to the desktop you also need to move any resources that it needs, so if it wants a folder named "datasources" you would have to move that folder as well, or set the current directory when you start the application.
Have you tried something like: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx or http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx ?
So
Directory.GetFiles(environment.currentdirectory + #"\DataSources\");

How to display images in smart device application

I am developing smart device application in C#. I am able to add the images in my application by sharing the folder. I am sharing the folder by doing some setting in the emulator. In the emulator by setting File -> Configure ->shared folder, I am able to retrive the images in my application by using Bitmap(). But I want to diplay these images from my application's folder. In my application I have added one folder by using add -> New Folder. In that I kept my images. But when I add them by using Bitmap I am getting error. I am using the code
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
to get the path of application & I am displaying the path in message box in emulator but is giving path as 'program file/managedappl'.So how to add the images from application's local folder? Is there any way? If there is only one way as I above mentioned then can my application successfully display the images on different mobile devices after deploying the application on them ? Can u provide me the code or link through which I can resolve the above issue?
If you look in the emulator: are the image files copied to the device upon running the application? This is necessary to get things working.
Then, you're using the correct code to determine the location of your program's exe file, however, you of course need to add the name of the folder that contains your images.
Let's say your application's exe resides in \Program Files\managedappl and your pictures reside in a folder pics within the program's folder. Then you determine the image path with:
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "pics");
After that you can append the name of an image file.
It is important to configure the image files in Visual Studio so they are copied to the device when running the application. If you look under "My Device" in the emulator (the mobile "Explorer"), you should see the following folder structure:
\Program Files\managedappl
\Program Files\managedappl\pics

Categories