I am working on a custom task for EG 5.1 -- Linux SAS 9.4.
I would like to either present a tree displaying the user's home directory (folders/subfolders) - to allow the user to select a location -- or
to capture the selection under the SASServer->Files-..
I have seen examples of capturing the selected library -- but cannot find any doc on getting the selected File.
Any suggestions on how to accomplish either task would be greatly appreciated.
Thanks,
Abbie
The task APIs don't offer a way to show the file structure on the SAS session, so you would need to create that part yourself.
Rather than use a SAS program to figure out the structure, you can use the IOM FileService->ListFiles API to accomplish this. You can get this from the SAS workspace, which you can obtain from the Consumer property.
You'll need to add some more assembly references to your project: SASInterop, SASIOMCommonInterop, and SASOManInterop. These are all in the EG application folder as well as in the SAS Integration Technologies client folder.
Sample code to get you started:
string ListedPath; Array Names; Array TypeNames; Array TypeCategories; Array Sizes; Array ModTimes; Array Engines; Array Mask; SAS.Workspace ws = Consumer.Workspace(Consumer.AssignedServer) as SAS.Workspace; SAS.FileService fs = ws.FileService; Mask = Array.CreateInstance(typeof(bool), 6); for (int i = 0; i < 5; i++) Mask.SetValue(true, i); Mask.SetValue(false, 5); // skip engines field fs.ListFiles("", SAS.FileServiceListFilesMode.FileServiceListFilesModePath, ref Mask, out ListedPath, out Names, out TypeNames, out TypeCategories, out Sizes, out ModTimes, out Engines);
Your work: parsing the array output here, then presenting files versus directories (folders). You can then build a UI that allows the user to drill in and pass the starting path (first argument to ListFiles) to find the contents of subfolders.
I'll be the first to admit this is cumbersome -- these array-based APIs were built for use with COM-based standards in mind and aren't very "object oriented". But they work!
Have you checked out the configuarion options in SAS Management Console?
In Server Manager - SASApp - SASApp Logical Workspace Server - SASApp Workspace Server - Properties - Options - Advanced Options you should see the following where you can specify a file path. It seems to work for me under Windows. Not sure about Unix.
Thanks SASKiwi,
I don't think I stated my problem well enough.
I have configured the File Navigation option correctly - to point to SAS User root.
The part that I cannot yet solve is:
Once the user has used the File portion of the SAS Server tree for navigation - ie made a selection in that tree,
is it possible to get that selection to my custom task?
If not, then I would need to write a sas program returns the directory structure and loads that into a treeview.
(I think)
The task APIs don't offer a way to show the file structure on the SAS session, so you would need to create that part yourself.
Rather than use a SAS program to figure out the structure, you can use the IOM FileService->ListFiles API to accomplish this. You can get this from the SAS workspace, which you can obtain from the Consumer property.
You'll need to add some more assembly references to your project: SASInterop, SASIOMCommonInterop, and SASOManInterop. These are all in the EG application folder as well as in the SAS Integration Technologies client folder.
Sample code to get you started:
string ListedPath; Array Names; Array TypeNames; Array TypeCategories; Array Sizes; Array ModTimes; Array Engines; Array Mask; SAS.Workspace ws = Consumer.Workspace(Consumer.AssignedServer) as SAS.Workspace; SAS.FileService fs = ws.FileService; Mask = Array.CreateInstance(typeof(bool), 6); for (int i = 0; i < 5; i++) Mask.SetValue(true, i); Mask.SetValue(false, 5); // skip engines field fs.ListFiles("", SAS.FileServiceListFilesMode.FileServiceListFilesModePath, ref Mask, out ListedPath, out Names, out TypeNames, out TypeCategories, out Sizes, out ModTimes, out Engines);
Your work: parsing the array output here, then presenting files versus directories (folders). You can then build a UI that allows the user to drill in and pass the starting path (first argument to ListFiles) to find the contents of subfolders.
I'll be the first to admit this is cumbersome -- these array-based APIs were built for use with COM-based standards in mind and aren't very "object oriented". But they work!
Chris,
Thanks so much - that was exactly what was needed.
I've unwrapped the directory entries - traversed and can now display the tree.
File isn't an option in a prompt?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.