I am aware that this is a question only @ChrisHemedinger may be able to answer, but i dare to ask anyway.
I am developing a custom task which creates a new file in the Windows file system (e.g. Excel). What i want to achieve is that after the custom task is executed a reference to this newly created file is added to the process flow.
I read the book "Custom Tasks for SAS Enterprise Guide Using Microsoft .NET" and tried the code from chapter 12 which seems to be close to the solution.
However this (simplified) code:
public ISASTaskStream OpenResultStream(int Index) { var memoryStream = new MemoryStream(File.ReadAllBytes(Settings.ExcelOutputPath)); var fileInfo = new FileInfo(Settings.ExcelOutputPath); return new StreamAdapter(memoryStream , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"// "application/vnd.ms-excel" , fileInfo.Name); }
writes a full copy of the file to the process flow and embeds the file into the workflow:
I know that there are plenty of ways to generate an Excel file, but what i would like to achieve is a linked reference in the process flow like the "export as step in process" task does:
So can anybody provide me a C# code snippet for adding a file reference or tell me which classes are involved?
Best Regards,
Andreas
I've looked into this a bit, and don't yet have a solution. But I'll share some things I've tried in case you want to hammer at them further.
First, I tried adding just a "file" as an output data item in the Task class.
public override System.Collections.Generic.List<ISASTaskDataDescriptor> OutputDataDescriptorList { get { ISASTaskDataDescriptor d = SAS.Shared.AddIns.SASTaskDataDescriptor.CreateLocalDataDescriptor ("c:\temp\sample.xlsx", "Sample.xlsx"); System.Collections.Generic.List<ISASTaskDataDescriptor> outList = new System.Collections.Generic.List<ISASTaskDataDescriptor>(); outList.Add(d); return outList; } }
Also added this an an attribute on the Task class:
[SAS.Shared.AddIns.CreatesDataDirectly(true)]
But no success. I think that EG doesn't add the result because it's not a true data reference...but I haven't debugged enough to verify.
Another approach to add a file to a project. With EG open, you can launch the SEGuide command with the /openfile command-line switch and add a file reference to the existing instance of EG. You could tell .NET to take the existing Process command and form your own variation with the command-line option. Example:
"C:\Program Files (x86)\SASHome\x86\SASEnterpriseGuide\7.1\SEGuide.exe" /openfile:c:\temp\sample.xlsx
But, EG automatically launches the Import Data task for most files that you try to add in this way...because of course that's what EG does with files like Excel spreadsheets. And even if you do get the file added to the project, it won't be linked from your task as output.
@AndreasMenrath - it sounds like you want to add a reference to an external file as a linked item in the flow, correct?
I'm not sure it's possible with the Custom Task APIs, but I will dig in and see if I can find something creative.
@ChrisHemedinger: exactly.
What i want is just a reference like when an external file is drag&dropped into the process flow from the Windows explorer or like the file reference in the "export as step in process" task.
Thank you for looking into the solution of this issue 🙂
I've looked into this a bit, and don't yet have a solution. But I'll share some things I've tried in case you want to hammer at them further.
First, I tried adding just a "file" as an output data item in the Task class.
public override System.Collections.Generic.List<ISASTaskDataDescriptor> OutputDataDescriptorList { get { ISASTaskDataDescriptor d = SAS.Shared.AddIns.SASTaskDataDescriptor.CreateLocalDataDescriptor ("c:\temp\sample.xlsx", "Sample.xlsx"); System.Collections.Generic.List<ISASTaskDataDescriptor> outList = new System.Collections.Generic.List<ISASTaskDataDescriptor>(); outList.Add(d); return outList; } }
Also added this an an attribute on the Task class:
[SAS.Shared.AddIns.CreatesDataDirectly(true)]
But no success. I think that EG doesn't add the result because it's not a true data reference...but I haven't debugged enough to verify.
Another approach to add a file to a project. With EG open, you can launch the SEGuide command with the /openfile command-line switch and add a file reference to the existing instance of EG. You could tell .NET to take the existing Process command and form your own variation with the command-line option. Example:
"C:\Program Files (x86)\SASHome\x86\SASEnterpriseGuide\7.1\SEGuide.exe" /openfile:c:\temp\sample.xlsx
But, EG automatically launches the Import Data task for most files that you try to add in this way...because of course that's what EG does with files like Excel spreadsheets. And even if you do get the file added to the project, it won't be linked from your task as output.
thank you for your suggestion. It is funny, but your suggested code works on my machine.
It successfully adds a referenced file to the process flow.
I think EG is case sensitive on the file name. Maybe that's the reason why your code did not run on your machine.
Using this just works fine:
var fileInfo = new FileInfo(@"C:\temp\Sample.xlsx"); ISASTaskDataDescriptor d = SASTaskDataDescriptor.CreateLocalDataDescriptor(fileInfo.FullName, fileInfo.Name);
Thank you and best regards,
Andreas
I also noticed a common C# error in your code:
you used the string "c:\temp\sample.xlsx" inside your code.
The backslash in a string is used for masking, so \t is translated to a tabulator character.
So using double backslashes "c:\\temp\\sample.xlsx" oder using a verbatim string with @"c:\temp\sample.xlsx" should also fix your code 🙂
Best Regards
Andreas
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.