I started programming Windows 8 apps in C#, and I need help to figure how to access files from within my app.
Premise: from what I learned till this moment, I know that as standard an app can access only certain folders (such as LocalFolder etc.). One way to overcome this is using a FileOpenPicker once and then use FutureAccessList to access programmatically the file.
Now my situation:
my pc is connected to a domain network
my app has the following capabilities: Enterprise Authentication, Internet (Client & Server), Private Networks (Client & Server)
Let's say that I have a file named im.jpg in C: and im2.jpg in a network share called share. I (my domain account) have the access to those files.
How can I access those files from my app without the use of FileOpenPicker?
Till now, I used WebRequest and WebResponse to download a file from an internet site (no problems), then I used WebRequest and WebResponse to access a file located in the LocalFolder of my app (still no problems), but now, if I do something like this:
WebRequest c = WebRequest.Create(#"file://C:\im.jpg");
WebResponse r = await c.GetResponseAsync();
I get a System.Net.WebException telling that I'm not authorized to access the file.
How can I use Enterprise Authentication to provide my domain credentials to the app? I didn't find much documentation about this on the MSDN, but from the little I found I think this capability is intended to be used in a situation like this. Also, is WebRequest the right path to follow? Should I try to access those files in other ways?
Thanks, Daniele
No matter, how you try to access the files from a Windows Store app, the permissions still apply, i.e. you can't access a random file on a disk or a file share if a user didn't grant you access before using a FileOpenPicker or a FolderPicker.
The best you can do is probably getting the user to access the root (of a disk or a share) using a FolderPicker and storing a reference to it in FutureAccessList. This way you'll be able to access all the files on that drive without any user intervention in the future.
Having a service as a workaround should work for shares (why not just use HTTP to allow file download instead?) but not for the local file system because your app can't access local network resources (i.e. services on localhost) unless you're running it from VS or using CheckNetIsolation.exe by hand.
I don't know about Enterprise Authentication, but opening a file is usually done using StorageFile::GetFileFromPathAsync. That also works with UNC path names when you have the permission..
Related
I am trying to run a macro-file that will be present in users desktop via my .net website, hence I would like to know how I can get the path of that macro file in my code and open it.
I am currently using following described code to get the path, and I think that this must be trying to take the path from server computer but I would like to get this from users computer, this particular macro file will open internet explorer and navigate to certain website and download a report to local computer hence I would like this to be run from users side.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Is it possible to get the path automatically or should i get that from user.
please provide suggestion.
You are hosting a website, which is using a web server like IIS and the user access the site using a browser like edge, chrome, now the file is in user desktop, so the main question remains,
Does the browser process have the access to the file system of the user
Mostly no, especially not via the call Environment.GetFolderPath(Environment.SpecialFolder.Desktop);, this will be good for running it on hosted sever, where w3p.exe process is accessing the file system with required permissions
For the end user desktop
You need to provide the file dialog box, let user select the file / directory and need to plan to serialize the file to the sever (upload) for doing any processing. You can binary serialize the file using a provider like protobuf, msgpack to achieve the necessary functionality
Code you have provided, is good for for the process where you have direct control, like Console, WPF, which runs on the system under certain permission and thus access the file system for processing
I am writing a Windows 8 App that requires access to files in another program's application data. I have read over Window's file permssion guidelines and did not see a way to do it. Is this even possible? If so, how would I go about doing it?
Not possible using winrt API. It is like IsolatedStorage per process.
File access and permissions in Windows Store apps
But using Hack it is possible to bypass sandbox environment.
How to bypass WinRT / Metro sandbox using simple trick.Sample + Guide
But such app will not pass windows 8 compatibility test while submitting to App Store.
This is not possible from windows store app, they are sandboxed and needs to declare capabilities such as access to internet, camera and similar, and you surley can't declare that you want to read other app data.
It's not possible if you don't know how to use .net for Windows 8 stor.
With this you get save location:
using Windows.Storage;
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
And with this you can retrieve data by app URI:
using Windows.Storage;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync("ms-appdata:///local/file.txt");
Source:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh967755.aspx?cs-save-lang=1&cs-lang=csharp#locations_all_apps_can_access
I found my answer. I can tell the user to select their user folder in the folder picker. Then once I get that permission, I can programmatiically navigate to the required files in the application data folder.
This answer depends on the other application and the type of files you're trying to access, but perhaps you can implement support for the Share contract and tell Windows what kinds of files you're willing to accept. The user then can use the other application and Share with your application if they choose. I'm not sure how viable this will be for your needs however as you don't provide much detail as to what data you're trying to get at.
Using XAML C# in Windows "Metro" Apps how do I go about playing a certain video file. Examples:
D:\video1.wmv
\\MEDIAPC\video2.wmv
The only way I managed to get this working so far is by using FilePicker, but I don't want to use this as I already have a list of files to play.
I have tried to use GetFileFromPathAsync but I keep getting permission / access issues
await StorageFile.GetFileFromPathAsync(#"D:\video1.wmv");
Apologies if this has been answered I just couldn't find an answer that fits my problem.
If your D:\ drive is a non-network resource try adding the Removable storage application capability. This can be accomplished by double-clicking on the Package.appxmanifest and navigating to the Capabilities tab. By default your application (assuming it is a Windows Store app) only has access to local files packaged with your app or files stored in local/roaming/temp folders (usually reserved for Application state).
If your data is stored on a Network resource that requires authentication you will want to enable the Enterprise Authentication capability.
You may also want to fiddle with the Home and Work Networks for the \MEDIAPC\ files if you aren't accessing resources that require network authentication.
Further Reads:
Accessing data and files
How to load data from files
App Capabilities Overview
I've got a webserver where people upload files. What I need to do is take those files and write them to a file share on the Active Directory domain. The problem -- the webserver is not on the domain.
So, how is the best way to do this? I would have thought this would be easy, something along the lines of create a connection with some credentials and do it. But apparently not. The closest I've found is Impersonation with WindowsIdentity.Impersonate, but everything I've read says that is a bad idea in a production environment.
Any ideas? I'm working on a solution that FTPs the files, but that's unsatisfying too, and a fallback plan.
I'm using c# and .net 4.0 in (obviously) a windows environment.
Edit: I should point out that I can't run servers (or services) that access the outside on that domain. The FTPing is a temporary workaround.
I would have another program probably a Windows service pick the files from the web service file location and move them to the active directory directory. I would probably have this process execute from the location where they are being copied to. Make them available in a share on the web server visible only to the process's user and admins.
I think that an FTP solution is better than using a Windows Share; however, I would think a web service of some type would be the best option for an inter-domain file exchange. That said, if you've got it working with WindowsIdentity.Impersonate -- why not use it? What context did you read that it was a bad idea?
Is there any way that you can map this file share as Network Driver. If you can do that, you don't need to manager Security and will be super easy to access these files as if they are local.
I need to load help files from my windows C# application and move/copy to other system (to its local drive). Application (same C# windows application) on the local system will use it for help.
What needs to be done to accomplish this?
I understand File.Copy() but i don't know, will it hold for remote system also?
File.Copy(
#"C:\localpath\file.hlp",
#"\\remotemachinename\localpathonremotemachine\file.hlp");
Or something along those lines... the second value is a UNC path.
And in case the target location needs a login and password, the following answer is applicable: Copy file to remote computer using remote admin credentials (Thanks to Carlos Rendon for finding it).
File.Copy() Copies an existing file to a new file.
The target can be a remote share (UNC).