Using an Excel file from onedrive in c# - c#

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.

Related

How to save data under AppData\Roaming instead of AppData\Local\Packages

Im developing a WPF aplication that saves some json under AppData\Roaming\MyAppFolder. During testing in VS2017 all was going as planned.
I generated the.appx for my project, installed and runned to see that no data was bing saved where I expected.
After using procmon I found out that the data was actually being saved under AppData\Local\Packages\Myapp_pn7t59nnjk55e\LocalCache\Roaming
Im using Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) to get the folder path.
Why exactly it changes when I run my app after installing using .appx?
Is there a way to actually save under AppData\Roaming?
Should I actually care about it?
The data is saved in the right location and your app will be able to read/load it without any problems.
That's where Windows 10 redirects AppData for modern applications, i.e. apps deployed using an appx package.

How to save file using Azure/Web API to folder on shared network drive

Currently trying to save a file to a folder on a network location.
network//location//folder/save-here
The WebAPI is connected though azure/VPN /Entity Framework, however I need to save the file on the protected network location, not just a record in the database.
I've started trying to use a Hybrid Connection, however I'm not sure it will help solve this issue.
What is the best way to achieve saving a file to a folder on a network location from a Web API/Azure?
Unfortunately, in the Application Service Plan you cannot mount a file share.
If you were using Azure's file share from Azure Storage, you could just save the file using the API. However, since you are trying to save to an on-prem file share, you might need to set up some kind of service (possibly another API) running on-prem than you would call and it would be able to save the file for you.

Trying to get Hard Drive Serial Number into a SQL Server via UWP app

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.

UWP app where to put static xml file in app

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!

Allow access to folder using C# via Active Directory user and Restrict access using windows explorer

I have some complex need basically related to Active Directory settings.
I have Shared Folder on Server.
We have software installed on the client machines. Now when client save the file, it should be save to the server machine's folder.
I have given Write Access to this folder and the file is being stored properly.
If I restrict View access then I can't see list of the files from the application.
If I am retrieving through the C# program then it should be retrieved. And if I see from the windows explorer then it should not be listed.
In short I want that the file read/write should be accessible from software only, but not from windows explorer.
I think you are looking for impersonation. More info at http://msdn.microsoft.com/en-us/library/w070t6ka.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
Similar thread: Get file to FileStream from remote path with another user credentials

Categories