datadaddy
(Scott Janisch)
August 27, 2024, 6:47pm
1
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
In a function:
//ref: Ice.Contracts.Lib.ServerPath
//using System.IO;
CallService<Ice.Contracts.ServerPathSvcContract>(serverPathSvc =>
{
List<Ice.Lib.ServerPath.Types.PathInfo> pathInfo = new List<Ice.Lib.ServerPath.Types.PathInfo>();
pathInfo = serverPathSvc.GetPaths(Epicor.ServiceModel.Utilities.SpecialFolder.CompanyData, "", false);
if(pathInfo.Count > 0)
{
string path = $"{pathInfo.First().FullName}\\testing.txt";
File.WriteAllText(path, "In t…
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
klincecum
(Kevin Lincecum)
August 27, 2024, 7:03pm
2
They changed the way it works a bit. I can show you later.
Olga
(Olga Klimova)
August 27, 2024, 7:10pm
3
this now returns only relative path, that is why it goes to the default wwwroot subfolder instead.
4 Likes
datadaddy
(Scott Janisch)
August 27, 2024, 8:26pm
4
okay, thanks, but is there a way to stop the error and accomplish the file write ?
Olga
(Olga Klimova)
August 27, 2024, 9:11pm
5
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
3 Likes
datadaddy
(Scott Janisch)
August 27, 2024, 9:22pm
6
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
2 Likes
klincecum
(Kevin Lincecum)
August 27, 2024, 9:43pm
7
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.
1 Like
datadaddy
(Scott Janisch)
August 28, 2024, 11:44am
8
@klincecum isn’t that what this is ?
In a function:
//ref: Ice.Contracts.Lib.ServerPath
//using System.IO;
CallService<Ice.Contracts.ServerPathSvcContract>(serverPathSvc =>
{
List<Ice.Lib.ServerPath.Types.PathInfo> pathInfo = new List<Ice.Lib.ServerPath.Types.PathInfo>();
pathInfo = serverPathSvc.GetPaths(Epicor.ServiceModel.Utilities.SpecialFolder.CompanyData, "", false);
if(pathInfo.Count > 0)
{
string path = $"{pathInfo.First().FullName}\\testing.txt";
File.WriteAllText(path, "In t…
that’s what I based my function code on that’s been working for over a year andit sudden;y broke after the upgrade
klincecum
(Kevin Lincecum)
August 28, 2024, 11:46am
9
It’s what that was .
The new code won’t be much different.
What is the path you would like to write to?
datadaddy
(Scott Janisch)
August 28, 2024, 12:32pm
10
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
klincecum
(Kevin Lincecum)
August 28, 2024, 12:35pm
11
Ok I’ll get ya fixed up.
There is no “problem” server side. They changed the way it works.
1 Like
Olga
(Olga Klimova)
August 28, 2024, 2:46pm
12
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])
datadaddy
(Scott Janisch)
August 28, 2024, 3:01pm
13
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
Olga
(Olga Klimova)
August 28, 2024, 3:14pm
14
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
3 Likes
datadaddy
(Scott Janisch)
August 28, 2024, 3:17pm
15
ok, sounds promising, about to give it a try, thx
datadaddy
(Scott Janisch)
August 28, 2024, 3:32pm
16
yep, that appears to work, thanks !
marking as solution
3 Likes