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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to upload file to sharepoint using x++

(0) ShareShare
ReportReport
Posted on by 2

 

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
/// 
/// Vendor Wise Outstanding
/// 
class VendorWiseOutstandingCSV extends CSVExport
{
    BalanceAsOnDate          ToDate;
    DialogField		            dfToDate;

    FormBuildStringControl      fbscMultiVendCode;
    FormStringControl           fscMultiVendCode;
    container                   vendCodeCon;
    Str1260                     vendCode;
    SysLookupMultiSelectCtrl    multiVendCodeCtrl;

    VendTrans                           vendtrans;
    AmountCur                           remainAmountCur;
    real                                NotDueBalance,PrePaybalance,AdvToVend;
    OfficeOpenXml.ExcelRange            cell;
    OfficeOpenXml.ExcelRange            cells;
    int currentRow			   = 1;

    /// 
    /// buildQuery
    /// 
    /// query
    query buildQuery()
    {
       
        QueryBuildDataSource	 qbdsVendTable, qbdsInventSite;/
        Query query		      = new Query(queryStr(VendorWiseOutstanding));
        qbdsVendTable			= query.dataSourceTable(tableNum(VendTable));
        qbdsInventSite			= query.dataSourceTable(tableNum(InventSite));

        vendCode = con2Str(vendCodeCon);

        if(vendCode)
        {
            vendCode = strReplace(vendCode,';',',');
            qbdsVendTable.addRange(fieldNum(VendTable, AccountNum)).value(vendCode);
        }
        return query;
    }


    /// 
    /// export
    /// 
    /// boolean
    boolean export()
    {
        #Properties
        MemoryStream memoryStream = new MemoryStream();
  
        QueryRun							qr;
        VendTable                           vendTable;
       
        using (var package = new ExcelPackage(memoryStream))
        {
            var worksheets			   = package.get_Workbook().get_Worksheets();
            var CustTableWorksheet	   = worksheets.Add('Vendor Wise Outstanding');
             cells				   = CustTableWorksheet.get_Cells();
           
            // Report header start
            currentRow   ;

            cell  = null;
            cell  = cells.get_Item(currentRow, 1);
            cell.set_Value('Vendor Code');

            cell  = null;
            cell  = cells.get_Item(currentRow, 2);
            cell.set_Value('Vendor Name');

            cell  = null;
            cell  = cells.get_Item(currentRow, 3);
            cell.set_Value('Vendor Group');
 
            cell  = null;
            cell  = cells.get_Item(currentRow, 4);
            cell.set_Value('MSME Yes/No');
           
            cell  = null;
            cell  = cells.get_Item(currentRow, 5);
            cell.set_Value('Vendor Hold Status ');     

            qr = new queryRun(this.buildQuery());
   
            while (qr.next())
            {
                vendTable   =  qr.get(tableNum(VendTable));
                currentRow  ;
                    
                cell  = null;
                cell  = cells.get_Item(currentRow, 1);
                cell.set_Value(vendTable.AccountNum);

                cell  = null;
                cell  = cells.get_Item(currentRow, 2);
                cell.set_Value(vendTable.displayVendName(vendTable));
                 
                cell  = null;
                cell  = cells.get_Item(currentRow, 3);
                cell.set_Value(vendTable.VendGroup);

                cell  = null;
                cell  = cells.get_Item(currentRow, 4);
                cell.set_Value(vendTable.MSMEVendor);

                cell  = null;
                cell  = cells.get_Item(currentRow, 5);
                cell.set_Value(enum2Str(vendTable.Blocked));
                
                  
            }
            package.Save();
            file::SendFileToUser(memoryStream, filename   '.xlsx');
        }
        return true;
    }


}

I have created this excel report , now as I run this report fron it dialog from frontend , it downloads like this ,

 but requirement is It should be saved to sharepoint directly instead of downloading

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, I think it's because SendFileToUser, you can check this article

    impulztech.com/.../

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans