BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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:

2015-12-14 13_57_24-SAS Enterprise Guide - SampleProject.egp.png

 

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:

2015-12-14 13_59_38-SAS Enterprise Guide.png

 

So can anybody provide me a C# code snippet for adding a file reference or tell me which classes are involved?

 

Best Regards,

Andreas

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

7 REPLIES 7
ChrisHemedinger
Community Manager

@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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
AndreasMenrath
Pyrite | Level 9

@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 🙂

ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
AndreasMenrath
Pyrite | Level 9

Hi @ChrisHemedinger

 

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

ChrisHemedinger
Community Manager
Well, I'm not going to question it. If it works for you, that's great!


It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
AndreasMenrath
Pyrite | Level 9

@ChrisHemedinger

 

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

ChrisHemedinger
Community Manager
Dang, you're right! Rookie mistake!


It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1321 views
  • 3 likes
  • 2 in conversation