Lock screen image change - c#

Here is my code:
Uri u = new Uri(#"C:\roomieUser\w3.tif");
Windows.System.UserProfile.LockScreen.RequestSetImageFeedAsync(u);
I am trying to change the lock screen in a Windows forms application. I have managed to use WinRT libraries in Windows forms application and there are two methods to change picture one is written above and other is as below
LockScreen.SetImageFileAsync(); //But it requires IStorageFile passed in method
I have pictures stored in "resources" folder, is there any method to convert/use these pictures as IStorageFile?
File path is correct but when I tries to run it shows an error message that
Element not found. (Exception from HRESULT: 0x80070490)

LockScreen.RequestSetImageFeedAsync is supposed to be called with a Uri pointing to an RSS feed, not an image. This method is deprecated in Windows 10.
You can use StorageFile.GetFileFromApplicationUriAsync to get files from the application's resources folder.

Related

C# “The system cannot find the path specified” on Share Drive

I am creating a Windows Application using C# which access a mapped drive (Z:\ is a mapped drive for a shared network folder) to grab the files inside the folder but return an exception error :
The system cannot find the path specified.
I have two different functions that will access this mapped drive. One function will display the image file found inside the shared drive to the windows application. Codes as below :
Display image file :
if (System.IO.File.Exists(photoPath))
{
pbImg1.ImageLocation = photoPath;
}
else
{
pbImg1.Image = eMapViewer.Properties.Resources.TempImage;
}
When double click on the image file on the windows application, the codes will call for another function to open the actual files on map drive :
Double click to open image file :
if (System.IO.File.Exists(photoPath))
{
Process.Start(#photoPath);
}
The first function (Display Image File) works without any issues. The image file is able to be displayed on the windows application. However, the second function (Double click to open actual image file) returns the exception error. I can confirm that both functions use the same photoPath of :
\\AOI\Backup\Mapping\picture.bmp
I was referring to this thread I found but cannot find the solution. Process.Start and "The system cannot find the path specified"
Can someone help on this?

Access to file denied on app's second run

I'm facing a weird issue, when trying to access file on SD card with code:
var path = #"D:\Test\test.txt";
try
{
StorageFile file = await StorageFile.GetFileFromPathAsync(path);
}
catch (Exception ex) { Debug.WriteLine($"File access failed due to {ex.Message}"); }
path = #"Test\test.txt";
StorageFile file2 = await (await KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault().GetFileAsync(path);
The file is on SD card, I've declared RemovableStorage capability, and added FileTypeAssociation. I can get the file when I first debug the app, but on the second run I get UnauthorizedException with the first StorageFile. Amazingly the second try to get the file via RemovableStorage works every time.
If I only restart the phone and debug app once again - it will again work, but still only for the first time.
Is accessing files by StorageFile.GetFileFromPathAsync() somehow limited?
Am I missing something?
UPDATE:
Seems like on newest version of emulator 10856 I get an exception on every run, what may mean that there will be no way to access file via full path.
The picker allows access because the user provided the file to you, not the path. A winstore app should not be dependent upon a users drive / folder layout, that is why you don't have authority to access files by absolute path. In this case, we should firstly allow access to removable devices in manifest file, then we should use system's RemovebleDevices folder to access files of allowable types.
Also it is strange you can work with the absolute path the first time. In my test device, I always get the UnauthorizedAccessException and "Access is denied" error if using absolute path. My device is of build 10586.11.

How can I open an image in the default photos app?

I have an app that captures images from the device's camera and saves them as StorageFiles to a folder in my app's roaming data. I've been trying to make a page that will open the image and show a preview, but I've been having many problems doing that, so I want to just open the image in the default photos app. However, I can't find any way to do that. Using await Launcher.LaunchUriAsync(new Uri(#"ms-appdata:///roaming/folder/img.jpg")); asks if I want to search for an app in the Store (searches for "ms-appdata"). Does the native Photos app for Windows (Phone) have a dedicated URI scheme? Also, I am targeting Windows 10 with this app, so the URI schemes (if any) may have changed.
Launcher.LaunchUriAsync is for launching an application using the URI scheme, this is not what you want.
Instead you'll want to launch an app based on a file:
Get the image as a StorageFile
var imageFile = await StorageFile.GetFileFromPathAsync(#"ms-appdata:///roaming/folder/img.jpg");
Then you tell the OS to launch an app to handle that file. It's then up to the user to choose which app to handle the image file:
var success = await Windows.System.Launcher.LaunchFileAsync(imageFile);
You can read more about "launching" files here.

WP8 copy SharedStorge file directly into IsolatedStorage

I am developing a Windows Phone 8 application but am having a lot of issues with file access permission exceptions hindering the approval of my application when ever I try accessing files in the "local" folder (this only happens after the application has been signed by the WP store, not when deployed from Visual Studio). To solve this I have moved all file operations to IsolatedStorage and this seems to have fixed the problems.
I only have one problem left though. My application needs to make use of the file extension system to open external files and this seems to involve the file first being copied to the local folder where after I can then manually copy it into IsolatedStorage. I have no problem in implementing this but it seems that a file access permission exception also occurs once the system tries to copy the external file into the local folder.
The only way I think this can be solved is if I can direct the system to directly copy into IsolatedStorage but I cannot figure how to do this or if it is even possible. It seems as if though the SharedStorageAccessManager can only copy into a StorageFolder instance but I have no idea how to create one that is directed into IsolatedStorage, any ideas?
PS. Do you think that the Microsoft system might be signing my application with some incompetent certificate or something because there is not a hint of trouble when I deploy the application from Visual Studio, it only happens when Microsoft tests it or when I install it from the store using the Beta submission method.
Below is a screenshot of the catched exception being displayed in a messagebox upon trying to open a file from an email:
EDIT:
Just to make it even clearer, I do NOT need assistance in figuring out the normal practice of using a deep link uri to copy an external file into my application directory. I need help in either copying it directly into isolatedstorage or resolving the file access exception.
Listening for a file launch
When your app is launched to handle a particular file type, a deep link URI is used to take the user to your app. Within the URI, the FileTypeAssociation string designates that the source of the URI is a file association and the fileToken parameter contains the file token.
For example, the following code shows a deep link URI from a file association.
/FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f0949a19
Upon launch, map the incoming deep link URI to an app page that can handle the file
// Get the file token from the URI
// (This is easiest done from a UriMapper that you implement based on UriMapperBase)
// ...
// Get the file name.
string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
// You will then use the file name you got to copy it into your local folder with
// See: http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.storage.sharedaccess.sharedstorageaccessmanager.copysharedfileasync(v=vs.105).aspx
SharedStorageAccessManager.CopySharedFileAsync(...)
I've inline the information on how to do this from MSDN http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987(v=vs.105).aspx
Read that documentation and it should be clear how to use the APIs as well as how to setup your URI mapper.
Good luck :)
Ok I figured it out. The "install" directory is actually restricted access but for some reason the Visual Studio signing process leaves the app with enough permissions to access this folder. The correct procedure of determining a relative directory is not to use "Directory.GetCurrentDirectory()" but rather to use "ApplicationData.Current.LocalFolder". Hope this helps!

C# launching an external app with metro api

I am trying to develop an app which launches a regular .exe application from metro app using launcher class. MSDN provided a sample here and a stackoverflow sample is here
The problem is that my metro gives error of "file not found" even the file is there. i have tried to place file on other drives as well but the problem persists
here is my code sample
// Path to the file in the app package to launch
string imageFile = #"E:\App.exe";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
/* error in the above line .it says file not found The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)*/
if (file != null)
{
// Launch the retrieved file
var success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not find file
}
LaunchFileAsync is for launching a file in its default program.
http://msdn.microsoft.com/library/windows/apps/Hh701461
I am not convinced it will work with an .exe
The correct usage is something like:
LaunchFileAsync("images\\picturesofcats.png");
This then opens a picture of cats in your default image viewer.
This will not work for an .exe due to sandboxing, and because .exe has no default opener.
There are a few tricks to get around this, see: Launching a Desktop Application with a Metro-style app
Generally, you are working against the design of Windows 8 to do this, so you might want to reconsider your approach.

Categories

Resources