0

Is there any way to make a hyperlink to a file that will open its contents or download it from the table it belongs? (In a sense, do exactly the same thing as AllowEdit but open/download the file instead.) Example:enter image description here

Where the Default Specification files are from files found on the customer:

enter image description here

Please note that what displays is the comment of the file. If anyone has any suggestions on how to display the file name instead, that would be appreciated as well.

EricP.
  • 489
  • 3
  • 21

1 Answers1

0

You can get the filename like this:

UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();

foreach (Guid note in PXNoteAttribute.GetFileNotes(cache, dacRecord))
{
    FileInfo file = uploadFileMaintenance.GetFileWithNoData(note);
    PXTrace.WriteInformation(file.Name);
}

To download the file, create a DAC field of string type. You can initialize the string to the file name in the FieldDefaulting or FieldSelecting event. Declare an Action and use the LinkCommand attribute in the ASPX file to make that field control a link.

In that Action event handler, you can redirect the browser to the file in order to download/open it:

    UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
    Guid[] notes = PXNoteAttribute.GetFileNotes(cache, dacRecord);
    
    if (notes != null && notes.Length > 0)
    {
        FileInfo downloadFile = uploadFileMaintenance.GetFile(notes[0]);
    
        if (downloadFile != null)
        {
            throw new PXRedirectToFileException(downloadFile.UID, true);
        }
    }
Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22
  • Thanks HB, I will give this a try in a couple days and let you know how it goes. – EricP. Oct 17 '17 at 18:38
  • If you need help with setting the LinkCommand and Link event handler, you can refer to this answer: https://stackoverflow.com/questions/26387291/how-to-create-a-hyperlink-user-field – Hugues Beauséjour Oct 17 '17 at 20:25
  • HB, where would I place the foreach statement and what would dacRecord consist of? What I mean by that is would dacRecord be defined by UploadFileRevision or some other table, or something else all together? – EricP. Oct 23 '17 at 13:20
  • Thanks HB! The link you shared answered my question for the most part. I forgot I could link an action to a column of a grid. As for the getting file names thing, I'm not really that worried about it. I think I'll just keep it the comment so the user can change what they see. Thanks again! – EricP. Oct 23 '17 at 15:33
  • DacRecord is an Object of a DAC class that contains the NoteID field. If you want to get the notes of SOOrder for example, you pass an SOOrder object to PXNoteAttribute.GetFileNotes. – Hugues Beauséjour Oct 23 '17 at 18:13