Click here to Skip to main content
15,913,166 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi In the program, inside the DataGridView is one of the photo fields that loads from the databases
Now I want to display a photo with a photo app like veiwer on the photo
Does anyone have a solution?

What I have tried:

[removed duplicate text]
Posted
Updated 12-Jul-17 0:47am
v2
Comments
Prifti Constantine 12-Jul-17 5:54am    
You want to show a preview of the photo inside the GridView?

The Photo app (like Viewer) requires a path to the photo to read the file and preview it. Since your photo comes from a database, Viewer app (or any other photo app) is unlikely to get access to it.

One solution to this will be to create a temporary file with a Guid based name. This will allow you to store the file for a while and then pass that temporary file to the Photo viewer. This is the only way you can solve it — as I believe photo viewers won't access database streams. :laugh:

You would need to write all the content from the database (binary content) to a file with the proper mime types and then store that as a temporary file in your local directories to provided the viewer with the access to this file. Create a temporary file from stream object in c# - Stack Overflow[^], you can later on delete it when no longer needed. :-)

Opening the photo viewer will be just simple task, you can use the Process type from System.Diagnostics and start a new process to show the file.
C#
Process.Start("viewer.exe", "parameter-temp-file-path");

As for the "when no longer needed" part, you can check when the process terminates, and then delete the file.

For more on the Process class, read: Process Class (System.Diagnostics)[^]
 
Share this answer
 
how to find
parameter-temp-file-path
in the gridveiw
 
Share this answer
 
Comments
LLLLGGGG 12-Jul-17 8:22am    
parameter-temp-file-path is the path of your saved temp file.
Suppose you have an image in the DB:
1. Copy it to your hard drive in the temp directory
For instance you can create a new temp file using GetTempFileName (https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename(v=vs.110).aspx) and then write all the data to that file (we call this file "asd6as7asd")

2. Use Process.Start("viewer.exe", "asd6as7asd"); to start the viewer

NB: never use again answers to ask for clarifications... those answers can get easily downvoted/reported. Use comments instead

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900