Launch from file when app already open in Universal app - c#

I am currently developing a specialized file editor application for the UWP platform. Right now, I have a file association so that a user can click on a file to load it into the app. This loads the file into the "working files" list which allows the user to edit multiple files in a single instance like Visual Studio Code.
Right now, if a user clicks on a file to open it will launch the app and load the file via the OnFileLaunched event. But what I also want to do is load a file when a user clicks on a file and the app is already open to load it into the program. What do I need to do for this?

Take a look on OnActivated method.
You can use OnFileActivated method to handle event when application is open and file clicked

Related

Include and launch PDF from C# Visual Studio Project

In my C# application i have a help button. When it's pressed I would like for the application to open up a PDF file in the systems default PDF reader, something I can do with a command like Process.Start("pathToPDF").
The problem is that I would like to include the PDF as a resource instead of calling an external file. I do not wish to copy the PDF to the users computer and do not want to host it online or on a NAS.
Right click on your project in the Solution Explorer, then add existing file and choose your pdf (if you cannot find it, make sure you are showing all files and not just .cs files etc.).
Click on the newly added item once in the solution explorer and in the properties window, you set Copy to Output Directory to Copy Always or Copy if newer.
Now you can open the pdf file as expected using Process.Start(filename.pdf);
The only Secure way to show a PDF without providing a file is to include your own Viewer Component (Ex. http://www.o2sol.com/pdfview4net/overview.htm)
Some components allow to load a PDF from Memory (as in a embedded Resource) directly into your Viewer Component, another way would be to create an encrypted binary file to ship with your application and encrypt/load when necessary.
As soon you want to show the PDF in an external viewer ,be aware that the User will have the ability to save the PDF anyway.
Maybe you can explain your reasons to not want to include the file, so we can suggest other solutions to you?
Update:
As noted in your comment, the goal is to have a clean installation.
It would be possible to embed the File as a resource, but then you would
have the problem that if you extract the file temporarily to display it, you can't really control the clean-up of that file, because it's locked by the PDF Reader Application.
So you would end up with the PDF File anyway ;)
What you can do to keep your Application Folder cleaner, is to not install the PDF under that Application Folder but under the "Common Documents" Directory.
For Example: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "MySoftware", "Help.pdf")
Which normally targets: C:\Users\Public\Documents\MySoftware\Help.pdf

how to open a folder by clicking a button in windows form application

How to open a folder by clicking a button in windows form application
I am developing a project in windows form application where I have created PDF file.By clicking a button, I want to open the folder of PDF file where I have saved it.
so how can I do this?
N.B: I don't want to run any .exe file. I only want to open a folder.
This one should work
System.Diagnostics.Process.Start ("c:\\");
it opens the c drive in explorer for you

Programmatically add own program to the context menu for files in a zip archive

This question applies to Windows operating system and the programming language C++ or C#.
In the Windows File Explorer: When I click on a zip archive I can see its file contents. When I right-click on one of these files, I see a context menu with the options: Open|Cut|Copy|Delete|Properties.
What do I have to do to register my program in this context menu?
When my program is called then I would like to open that file with it. I have code that adds my program to the normal file context menu of the windows file explorer and I have code to get data from a zip archive. The missing part is the user to enable to choose my application to start for a zipped file.

How to add a right-click extension/menu

Is it possible to install a right-click extension when in windows file browser, coded in C#?
I will take Winrar as an example:
When in the file browser, you can right click a file and Winrar will be in the list, giving a few options like "Unrar" "extract here" etc.
Is it possible to code the same thing, but when the user right clicks a file, to show my own app in the list, giving two options:
Open with -Myapphere-
Open with -Myapphere- text editor
The first option should start-up my application, and then run the file, being instructioned by the contents IN the file (start, pause etc)
The second option should open the file in my app's editor, DISPLAYING the contents of the file.
I already know how I am going to run / edit it, but how would I let my app now that it has to edit / run the file?
How would I install the right-click extension using the c# installer?
And then how would I open my app and the file with it, when clicked in the explorer?
And how would I make my program notice it is launched from a browser file?

Opening files from Windows Explorer in my Metro App

Coming from a Windows Forms background, I am used to being able to handle arguments, in the Program.cs file, passed to my application, when a user tries to open a Text file from Windows Explorer, so that my application can display its contents to the user.
However, in Metro style Apps, we don't have the Program.cs file anymore. We have the App.xaml or App.xaml.cs file.
Seeing as though I cannot find relevant documentation on this, I could just try doing it "the usual" way, in the App.xaml.cs file but I'm not even sure if that's the right way to go about it. I have Added the appropriate Capabilities and File type Associations to my Metro style App, but other than that I am don't know where to start.
How can we open a supported file from the Documents folder into our own Metro style Apps?
See How to handle file activation # http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh779669.aspx
You handle this by two specific steps:
Declare the file extension in your manifest. You can do this by opening the package.appxmanifest from Solution Explorer in VS, Going to the Declarations Tab, and adding the "File Type Association" declaration & relevant information.
In your activation handler, you will see the even has a "Kind" parameter. This will be "file" for a file launch (from explorer, or elsewhere). You will get the files in the "files" property on the same object.
Full details are here. Once you've got the files, you can use the standard Windows.Storage API's to access those files.
open package.appxmanifest in Solution Explorer.
Select the Declarations tab.
Select File Type Associations from the drop-down list and click Add.
Enter txt as the Name.
Enter .txt as the File Type.
Enter “images\Icon.png” as the Logo.
add the proper icons in the app package
and in c#, You need to handle OnFileActivated event
protected override void OnFileActivated(FileActivatedEventArgs args)
{
// TODO: Handle file activation
// The number of files received is args.Files.Size
// The first file is args.Files[0].Name
}

Categories