web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

(0) ShareShare
ReportReport
Posted on by 58

When trying to attach receipt file to Expense reports in EP 2012 I get the error " File upload failed. File write error on server. "

15264.error.PNG

I have already tried solutions provided such as 2012 R2, Attaching Receipts in EP / Document Management and AX 2009 - Expense management - Attaching receipts to expense report on Enterprise portal? but none works.

Any help is appreciated a lot, thanking in advance!

UPDATE:

it seems the problem is with the size of file, if I upload files with 1 KB size or less it gets uploaded, after some research got to know it is because of temp files, Question: where can I get temporary folder of enterprise portal so we can delete the temp files hence freeing up space?

I have the same question (0)
  • Verified answer
    kvnkk Profile Picture
    800 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    It's relating permissions and  Just have a look in to it business logic where the error coming and you will come to know the exact issue from your end.  \Classes\EPDocumentHandling\saveWebDocument  error thing at line number 156

    check file type which you are uploading is enable or not.

  • EagleClaws Profile Picture
    58 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    Thanks for your reply,

    there is no error in code, the code in line 92 gets executed which produces the error.

    Sometimes it uploads and it works, but mostly it generates error.

    #define.BUFFER_SIZE(4096)
    
    server static DocuValue saveWebDocument(DocuRef docuRef, IISPostedFile postedFile)
    {
        BinData binData = new BinData();
        int fileLength;
        str filePath;
        DocuType docuType;
        DocuValue docuValue;
        int dataLen;
        container data;
        FileIOPermission filePermission;
        boolean fileWriteError;
        str fileName;
    ;
        docuType = docuRef.docuType();
        if (postedFile)
        {
            fileLength = postedFile.contentLength();
            if (docuType.TypeGroup != DocuTypeGroup::Note)
            {
                if (fileLength > 0)
                {
                    if (Docu::validateFileSize(docuType, fileLength))
                    {
                        docuValue.initFromDocuRef(docuRef);
    
                        // Encode the File name before saving it.
                        fileName = new IISServer().htmlEncode(postedFile.fileName());
                        docuValue.OriginalFileName = Docu::getFileName(fileName);
    
                        [docuValue.FileName, docuValue.FileType] = Docu::splitFilename(docuValue.OriginalFileName);
    
                        if (Docu::validateExtension(docuValue.FileType))
                        {
                            if (docuType.FilePlace == DocuFilePlace::Database)
                            {
                                // Database save is not efficient, loads entire file into memory
                                // Database limits on filesize should be kept low
                                [dataLen, data] = postedFile.read(fileLength);
                                docuValue.File = data;
                                docuValue.insert();
                            }
                            else
                            {
                                // Overwrite the filename with a generated one
                                docuValue.FileName = smmDocuments::getNonExistingFileName(NumberSeq::newGetNum(DocuParameters::numRefDocuNumber(),true), docuRef.path(), docuValue.FileType);
                                filePath = docuRef.path()   docuValue.FileName   '.'   docuValue.FileType;
    
                                // File overwrite is not allowed
                                filePermission = new FileIOPermission(filePath, 'rw');
                                filePermission.assert();
    
                                // WinApiServer::fileExists will demand read access
                                // BP Deviation Documented
                                if (!WinAPIServer::fileExists(filePath))
                                {
                                    fileWriteError = false;
    
                                    while(true)
                                    {
                                        [dataLen, data] = postedFile.read(#BUFFER_SIZE);
                                        if (dataLen == 0)
                                        {
                                            break;
                                        }
    
                                        binData.setData(data);
    
                                        // Assert for write CAS permission has been done
                                        // BP Deviation Documented
                                        if (!binData.appendToFile(filePath))
                                        {
                                            fileWriteError = true;
                                            break;
                                        }
                                    }
    
                                    if (!fileWriteError)
                                    {
                                        docuValue.insert();
                                    }
                                    else
                                    {
                                        // Try to delete any partially written files
                                        // Assert for write CAS permission has been done
                                        // BP Deviation Documented
                                       
                                        WinAPIServer::deleteFile(filePath);
    
                                        // File write error on server
                                        error("@SYS113524");
                                    }
                                }
                                else
                                {
                                    warning("@SYS97284");
                                }
                            }
                        }
                        else
                        {
                            warning("@SYS97285");
                        }
                    }
                    else
                    {
                        warning("@SYS97286");
                    }
                }
                else
                {
                    warning("@SYS97287");
                }
            }
            else
            {
                warning("@SYS77591");
            }
        }
        else
        {
            throw error(Error::missingParameter(null));
        }
    
        return docuValue;
    }

  • kvnkk Profile Picture
    800 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    I am attaching xpo from my application and which is having some changes when compared to your code and check which may helps you.

    #define.BUFFER_SIZE(4096)
    
    server static DocuValue saveWebDocument(DocuRef docuRef, IISPostedFile postedFile)
    {
        BinData binData = new BinData();
        int fileLength;
        str filePath;
        DocuType docuType;
        DocuValue docuValue;
        int dataLen;
        container data;
        FileIOPermission filePermission;
        boolean fileWriteError;
        str fileName, fileNameWithoutType;
        System.Uri fileUri;
        SharePointAuthenticationType authType;
        Microsoft.Dynamics.AX.Framework.OfficeAddin.SharePoint.AuthenticationType docuAuthType;
        Binary tempFile;
        System.IO.MemoryStream tempStream = null;
        System.Exception ex;
    
        str endSlash(str _str)
        {
            return (strEndsWith(_str, '/') || strEndsWith(_str, '\\')) ? _str : (_str   '/');
        }
    
        docuType = docuRef.docuType();
        if (postedFile)
        {
            fileLength = postedFile.contentLength();
            if (docuType.TypeGroup != DocuTypeGroup::Note)
            {
                if (fileLength > 0)
                {
                    if (Docu::validateFileSize(docuType, fileLength))
                    {
                        docuValue.initFromDocuRef(docuRef);
    
                        // Encode the File name before saving it.
                        fileName = new IISServer().htmlEncode(postedFile.fileName());
                        docuValue.OriginalFileName = Docu::getFileName(fileName);
    
                        [docuValue.FileName, docuValue.FileType] = Docu::splitFilename(docuValue.OriginalFileName);
                        fileNameWithoutType = docuValue.FileName;
    
                        if (Docu::validateExtension(docuValue.FileType))
                        {
                            if (docuType.FilePlace == DocuFilePlace::Database)
                            {
                                // Database save is not efficient, loads entire file into memory
                                // Database limits on filesize should be kept low
                                [dataLen, data] = postedFile.read(fileLength);
                                docuValue.File = data;
                                docuValue.insert();
                            }
                            else if (docuType.FilePlace == DocuFilePlace::SharePoint)
                            {
                                docuValue.Type = DocuValueType::URL;
    
                                // Overwrite the filename with a generated one
                                docuValue.FileName = smmDocuments::getNonExistingFileName(NumberSeq::newGetNum(DocuParameters::numRefDocuNumber(),true), docuRef.path()   fileNameWithoutType  #FileNameDelimiter, docuValue.FileType);
                                filePath = endSlash(docuRef.path())  fileNameWithoutType  #FileNameDelimiter   docuValue.FileName   '.'   docuValue.FileType;//keep the ep file name same with client file name
                                docuValue.Path = filePath;
    
                                // Check the authentication type
                                authType = DocuSharePointParameters::GetAuthenticationType(filePath);
    
                                if (authType != SharePointAuthenticationType::SharePointOnline)
                                {
                                    try
                                    {
                                        // SharePoint save is not efficient, loads entire file into memory
                                        // Limits on filesize should be kept low
                                        [dataLen, data] = postedFile.read(fileLength);
                                        tempFile = Binary::constructFromContainer(data);
                                        tempStream = tempFile.getMemoryStream();
    
                                        docuAuthType = DocuSharePointParameters::ConvertAuthenticationType(authType);
                                        fileUri = new System.Uri(filePath);
                                        Microsoft.Dynamics.AX.Framework.OfficeAddin.SharePoint.DocumentUploader::UploadDocument(tempStream, fileUri, docuAuthType, false);
    
                                        docuValue.insert();
    
                                        // Clean up the temporary memory stream used
                                        tempStream.Close();
                                        tempStream.Dispose();
                                        tempStream = null;
                                    }
                                    catch (Exception::CLRError)
                                    {
                                        ex = CLRInterop::getLastException();
                                        if (ex)
                                        {
                                            if (ex.get_InnerException())
                                            {
                                                error(ex.get_Message());
                                                ex = ex.get_InnerException();
                                            }
                                            throw error(ex.get_Message());
                                        }
                                    }
                                }
                                else
                                {
                                    // Authenticating to SharePoint Online currently requires UI to be displayed
                                    error("@SYS4010239");
                                }
                            }
                            else
                            {
                                // Overwrite the filename with a generated one
                                docuValue.FileName = smmDocuments::getNonExistingFileName(NumberSeq::newGetNum(DocuParameters::numRefDocuNumber(),true), docuRef.path(), docuValue.FileType);
                                filePath = docuRef.path()   docuValue.FileName   '.'   docuValue.FileType;
    
                                // File overwrite is not allowed
                                filePermission = new FileIOPermission(filePath, 'rw');
                                filePermission.assert();
    
                                // WinApiServer::fileExists will demand read access
                                // BP Deviation Documented
                                if (!WinAPIServer::fileExists(filePath))
                                {
                                    fileWriteError = false;
    
                                    while(true)
                                    {
                                        [dataLen, data] = postedFile.read(#BUFFER_SIZE);
                                        if (dataLen == 0)
                                        {
                                            break;
                                        }
    
                                        binData.setData(data);
    
                                        // Assert for write CAS permission has been done
                                        // BP Deviation Documented
                                        if (!binData.appendToFile(filePath))
                                        {
                                            fileWriteError = true;
                                            break;
                                        }
                                    }
    
                                    if (!fileWriteError)
                                    {
                                        docuValue.insert();
                                    }
                                    else
                                    {
                                        // Try to delete any partially written files
                                        // Assert for write CAS permission has been done
                                        // BP Deviation Documented
                                        WinAPIServer::deleteFile(filePath);
    
                                        // File write error on server
                                        error("@SYS113524");
                                    }
                                }
                                else
                                {
                                    warning("@SYS97284");
                                }
                            }
                        }
                        else
                        {
                            warning("@SYS97285");
                        }
                    }
                    else
                    {
                        warning("@SYS97286");
                    }
                }
                else
                {
                    warning("@SYS97287");
                }
            }
            else
            {
                warning("@SYS77591");
            }
        }
        else
        {
            throw error(Error::missingParameter(null));
        }
    
        return docuValue;
    }

    Also look in to this post which is similar to your issue  :- https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/161202/error-when-attempting-ep-receipt-upload

  • Suggested answer
    EagleClaws Profile Picture
    58 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    Thank you very much kvnkk for your reply,

    I was able to solve the issue after noticing I'm able to upload only 4 KBs because the BUFFER_SIZE is  defined 4096, I had to change it to a size bigger than 4 KBs, hence I was able to upload.

    Noticing your code it has the same 4096 as buffer_size and you're able to upload, but in my case I had to change this to a bigger size, I don't know how it works in your case.

  • kvnkk Profile Picture
    800 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    Please mark your solution as an answered, which may help others who are facing same issue.

    Also please verify this setup Organization administration\Setup\Document Management\Document Management Parameters 

    pastedimage1577182568931v1.png

  • EagleClaws Profile Picture
    58 on at
    RE: Attaching Receipts in EP Expense Report error " File upload failed. File write error on server "

    The option to mark my solution an an answered is not available/visible to me.

    The setup in my system which follows as setup Organization administration\Setup\Document Management\Document Management Parameters  is same as yours.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,157

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 883 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 674 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans