Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to upload file to sharepoint using x++

(0) ShareShare
ReportReport
Posted on by

 

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

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to upload file to sharepoint using x++

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans