Sunday 15 February 2015

c# - NullReferenceException only when opening images from database -


I have a table in my database that stores all types of files.

A list view is shown in the file names and when a user clics on one of them then it has been opened by the registered application based on the file extension.

This code is:

  if (listViewArchivos.HasItems) {dynamic result = list view archives. Selected item; Var nombre = path. GetTempPath () + admin.buscarNombreArchivo ((int) result. Id); Var byte = admin.buscarArchivo ((int) result. Id); Try ({var author = new binaryRITR file (nambre, flammod.creative)) {author. Write (bytes);} var p = Process.Start (nombre); p.WaitForExit ();} hold (exception exc } {InterfazUtil.error (exc.Message); // This is a MessageBox} Finally {File.Delete (nombre)};}}   

This docx, pdf, txt, etc. But when I try to open an image, the file is successfully opened from the Window Photo Viewer (Windows 7), but threw a NullReferenceException.

If I initiate I close the bar WPV and then the message box has been removed from the Temp folder.

If I close the first message box, then the image disappears from WPV and I close the WPV file

Now, if I remove the catch block, the file has been successfully opened by WPV and after closing it the file has not been removed from the temporary folder.

It seems that

TIA

Edit:

Exception

Pre> p.WaitForExit ();

According to this MSDN:

... you < Em> no process is already running when returning the process object.

I found it on the forum related to the nature of WindowsPhotoViewer:

Basically, Windows Photo Viewer is a part of Windows Explorer, and usually Explorer. XC runs in the process. In fact, are you calling a photo viewer? Actually there is only "preview" action for images. This is not a standalone application, and it does not make any sense to open any images or images.

As such, you can not get the process due to the object it is already running based on this fact That explorer.exe is already running. Finally, I think this means that if your images are opened in Windows Pfever, then you will be able to create not WaitForExit () work because the owner never runs out.

No comments:

Post a Comment