We are a Public Cloud company and we created a Function to generate an ACH file for our bank. We would like the file to be saved in the “Server File Download” Folders however we are struggling with how to do that.
Anyone tackled that? or have any suggestions?
DaveO
1 Like
Have you looked into using Azure File Share? This is configured by support for Cloud and works great for Bartender and other files plus it is easy to map on a client computer.
1 Like
Mr. Dan: Thank you for the suggestion and welcome back - i have not seen you in a while.
DaveO
This seems to be working:
string remPath = @“<CompanyID>\Users" + Session.UserID + @”";
klincecum
(Kevin Lincecum)
November 12, 2024, 4:21pm
5
//CompanyData Folder
var selectedSpecialFolder = Ice.Lib.FileName.ServerFileType.Process;
//Choose a filename
string Filename = "YoAdrian.txt";
//Have the system provide us with a unique filename from the proper folder
string fullFilePath = "";
CallLibrary<Ice.Lib.FileName>(f => fullFilePath = f.Get(Filename, selectedSpecialFolder));
//Some data
string yourData = "Hello DaveO!";
//Write file
Ice.Lib.writeFileLib.FileWrite(fullFilePath, yourData);
This should get you going for now.
UserData will be: Ice.Lib.FileName.ServerFileType.UserData
2 Likes
Mr. Kevin: You are a rock star
Thank you,
DaveO
2 Likes
klincecum
(Kevin Lincecum)
November 12, 2024, 4:35pm
7
I had it written already.
Stole from myself from here:
https://www.epiusers.help/t/dump-database-table-to-csv-file-in-epicordata-folder/117317
Keep in mind, some of this may change in the future as they are changing the way file reading and writing works.
datadaddy
(Scott Janisch)
December 11, 2024, 3:19pm
8
Have you tried to create a subfolder, for example I used to be able to create:
/ChangeForms/ChangeForm.eml
Previously if the folder part did not work, it created it, now it does not
(discovered this testing in our Pilot environment 2024.2.4 in prep for our production environment upgrade to same version this weekend)
this is my function code (based on Kevin’s, long time ago) that used to work
{
addToResult("TestFileCreate, FileName: " + iFileName);
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;
}
var userDataPath = Ice.Lib.PathHelper.GetFolderPath(baseFolderType);
var fullFileName = System.IO.Path.Join(userDataPath, iSubFolder + "/" + iFileName);
addToResult("fullFileName: " + fullFileName);
// iBuffer contains leading and trailing "s
// caused by syntax required in event handler for passing along the previous functions results
// so we remove them now
if (iBuffer[0] == '\"')
{
iBuffer = iBuffer.Substring(1, iBuffer.Length - 2);
}
// replace left or right double quotes with normal double quote
iBuffer = iBuffer.Replace('\u201c', '"');
iBuffer = iBuffer.Replace('\u201d', '"');
// 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(fullFileName, bytes);
addToResult("Wrote text");
}
catch (Exception ex)
{
oSuccess = false;
oMessage = "Error creating file: " + ex.Message;
if (ex.InnerException != null)
oMessage += " / " + ex.InnerException.Message;
}
finally
{
addToResult("Finished, success: " + oSuccess.ToString());
}
1 Like
klincecum
(Kevin Lincecum)
December 11, 2024, 4:35pm
9
That should have never worked.
I seem to recall playing with Swagger on this endpoint and accidentally creating some folders, but that was quite a while ago. (10.2.###)
datadaddy
(Scott Janisch)
December 11, 2024, 4:47pm
11
okay, but it did, regardless, I removed the subfolder part and should be ok now, thanks
klincecum
(Kevin Lincecum)
December 11, 2024, 5:01pm
12
Well you could just add some code to create the folder.
Action<string, byte[]> WriteAllBytesWithDirectory = (fullPath, buffer) =>
{
string directory = Path.GetDirectoryName(fullPath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
File.WriteAllBytes(fullPath, buffer);
};
2 Likes
datadaddy
(Scott Janisch)
December 11, 2024, 8:00pm
13
Thanks @klincecum , that worked !
2 Likes