I have a UWP app I'm working on and in that app I have an .XML file that I need to read from sometimes. I've just been hard coding the location of the file while debugging but now that I want to try to run the app on a remote device I need do actually put that file somewhere and be able to read from it.
Is there a place where this file should go where whether I'm running the project locally or on a remote device I'll have access to?
You can actually put it anywhere inside your project. It's perfectly fine. Check this out: http://www.c-sharpcorner.com/article/read-xml-file-in-windows-10-universal-app/
But the other thing that I'd suggest to you is to save the XML file in the local storage: http://jamescroft.co.uk/blog/uwp/how-to-implement-local-storage-in-universal-windows-apps/
Hope it helps!
Related
So I'm trying to make a program that uses an excel file to get some data.
I'm trying to make it so i can update data while the application is running, but i have no clue on how to get the file from onedrive.
The application is running c# .net 6. Reading the data from a local path is no issue.
I want to know if there is a better way than onedrive, or how i would read the excel data.
Scenario: The application will run on a remote server. I need to update the excel file from my own pc. I would rather have the file locally and have onedrive automatically syncing it on the machine, than having to remote desktop to the server.
UPDATE:
I've now tried troubleshooting and it seems like the path can't be found. I've written the path in console to see if it uses the correct path on the server as well, when using path in file explorer, i go directly to the file.
So having this issue i was not thinking about the posibility of not having the rights to access the file.
To fix the issue i had to go into application pools and then edit the application pool i was using, for that service, to a user having rights to the folder it tried to access.
I'm a relatively new Developer building my first app.
Right now I'm in the process of developing a UWP app and I am needing to get the Hard Drive Serial number from the PC from the Views (OnNavigatedTo), then after a few more fields are filled out, to then save all values to a SQL Server.
What I have discovered up to this point:
Grabbing some values like Hard Drive SN are not so easy with UWP.
I don't seem to have access to Registry HKLM via UWP
I can grab it very easily with PowerShell, and write it to a JSON or XML file. which I plan to do with a Service Account when PC is imaged.
I Don't know where to put the file where the App can see it.
Writing to Sql Server can only be done by creating a webservice and making HTTP / JSON calls via App. (I have this part setup but have not started accessing it via app yet)
So the part I really need help with I guess, is Where to Put JSON/XML file that App will be able to see and read from. Unless of course, someone knows of another way to get Hard Drive SN into a UWP app.
Thanks for Any Help
The recommended way to do this (if you want to go to the Windows Store) is to use a FileOpenPicker and have the user choose the file manually.
If this is for side-loading only (not going to the Windows Store) you can write the file to the user's Documents folder and then the UWP can read it using documentsLibrary capability without any user intervention. You could also use a fullTrust extension to run the PowerShell script and to put the file in the app's data folder. You can check out the Desktop Bridge docs for more info on fullTrust extensions.
Currently, I have a web based C# application (ServiceStack) that has an XML file it relies on to generate things client side. I no longer want to store this file on the client side. I need a way to use the repository I wrote to edit the file when it is stored on the server.
I have tried the following:
Finding the file location of XML when in the service. (it says that the service current directory is windows/system32, because it's running as a service. Makes sense now.)
Putting the file in the same project side by side. (same problem)
This already works:
Retrieves XML ( With hard coded path :c )
Deserialize XML
Add/Remove to XML as needed
Save
The key thing to this problem is it must live where the API lives. I don’t think that I am understanding the way this works very well, and I'd greatly appreciate some help.
Use System.Web.Hosting.HostingEnvironment.MapPath to find the path of the file relative to your application, assuming it's hosted via IIS.
In ServiceStack you'd normally use the Virtual File System to resolve files, e.g:
base.VirtualFileSources.GetFile("path/to/file.xml").ReadAllText()
Otherwise if you just want the path you can use IAppHost.MapProjectPath() available from v4.5.4 to resolve a file path relative to your WepApp consistently in all App Hosts, e.g:
HostContext.AppHost.MapProjectPath("~/path/to/file.xml")
I have written a winform app and have created a installation program using Inno Setup so that a custom file extension is associated with it.
The application is setup so that if the associated file type is double clicked then the application automatically opens and loads the file. This works fine from if the file is double clicked from the desktop or file explorer.
However, we have noticed an issue when trying to open a file attachment from inside Outlook. This error is being generated:
System.UnauthorizedAccessException
I have caught the error in my application and checked the file path that is supplied to the program. It doesn't exist in the file system (when I try to browse to it).
C:\User\MyUserName\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook\MXIIIP00\MyFilename.CustomExtension
The section after ...\Microsoft\Windows\ doesn't exist (as far as I can see).
Has anyone else encountered this issue and know how to solve it?
UPDATE:
If I open a dos prompt - I can actually get to this location even though it is not shown in Windows Explorer.
UPDATE 2:
If I copy the path directly into Windows Explorer I can see the files here too. However if I double click the file from here - my application still cannot load the file.
UPDATE 3:
The file saved by Outlook (and that my app is trying to open) appears to be empty. Which would explain why my app can't process it. Outlook appears to be doing something to the file when I send it. It starts off as 72KB when I send it, but when I receive it - it is 252B.
It´s a problem of AUTHORIZATION.
You may try to run your app AND the Outlook in ADMIN MODE to get success - at least it´s mandatory, run both at the same authorization level.
Or even try to open your attachment in the Windows TEMP folder... but I guess you won´t get it from within Outlook if you don´t, programatically, extract the attachment to that folder and open it.
Okay so as it turns out there was two issues here.
The first was to do with how I was testing this feature. To simulate the file being sent to a customer I used Outlook to send an email with my file as an attachment to myself. For some (as yet unknown) reason, Outlook takes it upon itself to send me an empty file. When I logged into an external email client and sent the file to Outlook the file remained intact.
However, my application still wouldn't open it.
The second issue was the temporary file being created with the Read Only attribute being set. Once I set up my application to turn this off, it all worked fine.
I have a folder that will contain a temporary file that will be created by web service. I want the file to be converted by .exe program I have via command line. Now, I have already generated web service that will create file and store in one specific folder.
Here is the scenario:
Web service receive amr byte data from my mobile app.
Web service deletes all files existing in the folder. (to remove .amr file and .mp3 file that was generated from the previous round)
Web service create new .amr file in the folder.
Windows Service detects that there is a new file created. It call converter.exe. Once complete, it creates .mp3 file in the same folder.
Now, I have no problem with step1-3. The problem is step4, which I need to convert .amr file to .mp3 file. In order to do this, I need to pass some dos-command to converter.exe. I found that it is impossible for me to do it from my web service, so I am thinking of creating C# Windows Service that will watch the folder storing the files. Is it possible to create Windows Service that is able to detect new file creation and run converter.exe as soon as a new file is created ? I did search on the Internet and found that I may be create Windows Service with FileSystemWatcher, but i am just not sure if it will be possible.
The reason I found when trying to execute converter.exe from web service is about permission. I did everything but still can't make it success.(Using Web Service, converter.exe is shown on the process list in task manager as local system, but it will not be executed because of some security reason...) Hope there will be no security problem when I try to execute converter.exe using Windows Service.
Thanks in advance for all answers and suggestions :)
System.IO.FileSystemWatcher will do the trick. The Created event will tell you when a file has been created in the directory you're watching. To start your conversion program, take a look at the System.Diagnostics.Process.Start method. Both of these should work fine in a Windows service.