0

i create a very simple photo viewer using c# wpf i just need to open the image directly into my app like default windows photo viewer.

so i need to pass the image file as parameter to my app

i found This Question but it for winforms not wpf.

i hope that you could help me.

sorry for bad English.

1
  • 1
    Google File Association c# Commented Nov 10, 2014 at 14:17

1 Answer 1

4

To handle file open - triggered for example when double-clicking a file in Windows explorer - simply run the following C# code when the application has been started (e.g. in the main window's "Loaded" event):

var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { var fileName = args[1]; if (File.Exists(fileName)) { var extension = Path.GetExtension(fileName); if (extension == ".MyDocumentExtension") { // TODO: Open file from fileName } } } 
Sign up to request clarification or add additional context in comments.

4 Comments

i have made an small edit . now it works . Thanks alot
@AhmedTarek, this answer is about how to pass file as parameter to your program, which for me is different to your question: to open the image directly into my app like default windows photo viewer.. You may want to update your question.
Yes, the question for me means "How to register a file association in Windows" but is actually "How to load file from application arguments"
So, you changed it back to the original?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.