Server file upload, broke after latest upgrade (Saas)

Had this in place for about a year now, never any issues until the upgrade this past weekend.

Have a function that follows this from @klincecum

now it’s not writing the file, and if I test run the function with the rest helper I get this from my trace I implemented:

Could not find a part of the path 'C:\\inetpub\\wwwroot\\Server\\Server\\ChangeForms\\ChangeForm.eml'

I am using SpecialData.UserData for the folder type/name.

Does that path make sense when I’m Saas?
And why isn’t “UserData” part of the path ?

I created a support ticket already but just reaching out in case others have ideas

Thanks, Scott

They changed the way it works a bit. I can show you later.

this now returns only relative path, that is why it goes to the default wwwroot subfolder instead.

okay, thanks, but is there a way to stop the error and accomplish the file write ?

Internally it is rewritten something like

string userDataPath = PathHelper.GetFolderPath(Epicor.ServiceModel.Utilities.SpecialFolder.UserData); 
string absoluteFileName = Path.Join(userDataPath, FileName);

Also, add using Ice.Lib; to the usings.

But I myself did not try it in BPM/functions. Here @klincecum should already know better :slight_smile:

yes, hopefully @klincecum can poke it with a stick also, he’s great at that.

I should add, I see from my trace that the path is relative because all I get back when I use the service to get the path is “ChangeForms” (the name of my folder in UserData folder), and all I do is append the filename and write the data…simple…

But the exception it’s throwing gives the longer full path :thinking:

I’ve already got it figured out and done somewhere, but I’m about half useless today.

I’ll drag my ass up tomorrow and show it.

@klincecum isn’t that what this is ?

that’s what I based my function code on that’s been working for over a year andit sudden;y broke after the upgrade :face_with_thermometer:

It’s what that was. :rofl:

The new code won’t be much different.

What is the path you would like to write to?

I am trying to write to Server/UserData/ChangeForms

Below is my code, been working for over a year

try
{
   CallService<Ice.Contracts.ServerPathSvcContract>(serverPathSvc =>
   {
       List<Ice.Lib.ServerPath.Types.PathInfo> pathInfo = new List<Ice.Lib.ServerPath.Types.PathInfo>();
       addToResult("Created pathInfo List");
       
       Epicor.ServiceModel.Utilities.SpecialFolder baseFolderType;
       
       // there are other folder types available in the enum
       switch (iBaseFolder)
       {
          case "Report":
             baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.Report;
             break;
          case "UserData":
             baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.UserData;
             break;
          case "CompanyData":
             baseFolderType = baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.CompanyData;
             break;
          case "Admin":
             baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.Admin;
             break;
          default: 
             baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.UserData;
             break;
       }
       
       // this will this create the sub folder if it doesn't exist
       pathInfo = serverPathSvc.GetPaths(baseFolderType, iSubFolder, false);
       
       foreach (var onePath in pathInfo)
       {
           addToResult("Path found: " + onePath.FullName);
           
           string path = $"{pathInfo.First().FullName}\\";

           path += iFileName;
           
           // File.WriteAllText(path, iBuffer);
           
           // changed to writing all bytes because if buffer contains ", string is ended and email missing info
           byte[] bytes = Encoding.ASCII.GetBytes(iBuffer);
           File.WriteAllBytes(path, bytes);
           
           addToResult("Wrote text");
       }
       
   });
}
catch (Exception ex)
{
   oSuccess = false;
   oMessage = "Error creating file: " + ex.Message;
   if (ex.InnerException != null)
       oMessage += " / " + ex.InnerException.Message;
}
finally
{
}

I have a ticket open, feedback so far has been there might be a problem on their side,
the exception that is thrown says:

Could not find a part of the path 'C:\\inetpub\\wwwroot\\Server\\Server\\ChangeForms\\ChangeForm.eml

see where is says \Server\Server ? that should be \Server\UserData

Ok I’ll get ya fixed up.

There is no “problem” server side. They changed the way it works.

so to each of your case statement you add something like

with specific enum value

and after all you do Path.Combine(basePath, [path you have already])

But what is “PathHelper” object, I think because you’re looking at internal code as you mentioned I don’t have access to that ?

In the Ice.Lib.ServerPathSvc that I have access to it only has “GetPaths” and “ServerDirectoryExists” endpoints to call

see above, you should add using Ice.Lib.

This code works fine for me from BPM

var baseFolderType = Epicor.ServiceModel.Utilities.SpecialFolder.UserData;
var userDataPath = Ice.Lib.PathHelper.GetFolderPath(Epicor.ServiceModel.Utilities.SpecialFolder.UserData); 

var absoluteFileName = System.IO.Path.Join(userDataPath, "subfoldername/anothername/file.ext"); 

throw new Exception(absoluteFileName);

It throws full path:
C:\EpicorData\Users\MANAGER\subfoldername/anothername/file.ext

ok, sounds promising, about to give it a try, thx

yep, that appears to work, thanks !
marking as solution