1

I was wondering if someone could help me with the following problem.

I have uploaded a couple thousand files (MSG, PDF, DOC, DOCX, XLS, XLSX etc.) into our Oracle database as we need to start saving our files into the database.

I want to know if it is possible to basically open a selected file from the database into memory and then proceed to open the file with the default application without having to save the file onto the local disk each time.

This would mean that if a user selects to view a PDF document, it should open with Adobe Reader, a Word Document should open with Word and a MSG file should open with Outlook, etc.

I have searched through the internet and have been unsuccessful in my attempt to find information to help me in this matter.

3
  • https://en.wikipedia.org/wiki/List_of_RAM_drive_software In any case the local software must to have access to the locally available storage to deal with some data. Commented Jun 17, 2015 at 9:42
  • 4
    You're actually asking how to give the Windows Shell a stream (BLOB stream) to open it with the program associated with an extension. That won't work. The associated programs would have to be able to receive streams on input which is not what they do. Use temporary files. Commented Jun 17, 2015 at 10:41
  • Possible for OLE Compound Document - examples are DOC and XLS (but not DOCX and XLSX) as much as some other formats (MSC for what I remember). For this subset that is possible, but it hardly is worth implementing it in general. Programs work with files. Even this very your program - does it take some virtual abstract data from the Windows on the launch or not? So you would have to make a file on disk, a temporary file on HDD, or maybe a temporary drive in RAM, or you can implement your own little network drive (WebDAV) - but it should look like a file for the target application Commented Jun 17, 2015 at 11:39

1 Answer 1

1

Okay

I have managed to get a solution that works perfectly.

I just needed to add 'ShellAPI' to the uses clause at the top of the form in order for Delphi XE2 to recognize the 'ShellExecute' command.

Below is my code:

procedure Tdms_displayfiles_frm.download_btnClick(Sender: TObject);
var
  blob: TStream;
  filename : string;
begin
  blob := dms_download_ods.CreateBlobStream(dms_download_ods.FieldByName('fil_file'), bmRead);
  try
    blob.Seek(0, soFromBeginning);

    with TFileStream.Create('c:\Temp\' + dms_download_ods.FieldByName('fil_sequence').AsString + '_' + dms_download_ods.FieldByName('fil_filename').AsString, fmCreate) do
      try
        CopyFrom(blob, blob.Size)
      finally
        Free
      end;
  finally
    blob.Free
  end;
  filename := 'c:\Temp\' + dms_download_ods.FieldByName('fil_sequence').AsString + '_' + dms_download_ods.FieldByName('fil_filename').AsString;
  ShellExecute(0, nil, PChar(filename), nil, nil, SW_SHOWNORMAL);
end;

So far I tried it with the following file formats: PDF, MSG, DOC, DOCX, XLS, and XLSX and all files open with their default programs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.