Skip to content

Create and download a file from controller using HMI Button

Hello,

I know there are variants of this issue already answered but I cant figure out how to manage mine specifically.

My need is when the user presses a button on the HMI I want my C# Program to overwrite a specific file ("myReport.txt") in a specific file path and then download that to the device that pressed the button.

My problem though is that when I try to use "File.WriteAllText(filePath, textData);" on the paths mentioned in the previous solutions, then my plc produces an error. Maybe there is a problem with the write permissions?

Also, I do not care if a user with no access can download the file but I do not want to compromise the security of the project solution + C# code that is running on my PLCnext.

Is that possible? Any ideas?

Thank you in advance.

Comments

  • Hi.

    Am I right in saying that there are two independent issues here?

    1. Writing a file to the PLC.
    2. Transferring the file from the PLC to the HMI device.

    For the first issue: What path(s) are causing errors? Can you give more details of what the error looks like?

    For the second issue: What method are you using to transfer the file to the HMI device?

  • edited February 2024

    Hello,

    I do not think they are independent, because with a valid filePath I can write to the PLC but I do not think that that filePath will be a valid path that can be stored a file to be downloaded.

    I used the following filePath because this is the one that was used in the previous answer for the file to be stored to.:

    public const string reportFilePath = "/projects/PCWE/Services/Ehmi/ehmi/myReport.txt";   // ../opt/plc/XXX is the base path

    That provided the following error:

    IF I use -> public const string reportFilePath = myReport.txt";   // ../opt/plc/XXX is the base path THEN the file is created correctly but I do not think that I can use this file path to download it afterwards.

    I haven't yet used a method to transfer the file to the device from which the user clicked the HMI button.

    I appreciate the swift answer!

  • Please try without the leading slash, which indicates that the path should start at the root of the directory tree (/), not from the current directory (/opt/plcnext/)

    public const string reportFilePath = "projects/PCWE/Services/Ehmi/ehmi/myReport.txt";
    
  • Alright, I feel embarrassed now, thank you Martin once again.

    So, regarding the security issue:

    Does this way of working around the problem cause any security issues regarding my project solution + C# code?

  • No, I don't think that Oleksandr's suggestion in that other conversation causes any security issues for the project.

Sign In or Register to comment.