Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:54:59+00:00 2026-06-14T08:54:59+00:00

Does any one know how to use the package.Saveas function? package.SaveAs(tempFolderPathAlt + saveas +

  • 0

Does any one know how to use the package.Saveas function?

package.SaveAs(tempFolderPathAlt + saveas + ".xlsx");

At the moment this is underlined in red with the following error:

The best overloaded method match for
‘OfficeOpenXml.ExcelPackage.SaveAs(System.IO.Stream)’ has some invalid
arguments

At the moment i’m saving the file in the following way.

FileStream aFile = new FileStream(tempFolderPathAlt + saveas + ".xls",    FileMode.Create);
byte[] byData = package.GetAsByteArray();
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(byData, 0, byData.Length);
aFile.Close();

But this way the package remains open and i cant work with files it has used.

The save as will close the package properly, but its not accepting my file path.


Edit

I tried this:

using (FileStream aFile = new FileStream(tempFolderPathAlt + saveas + ".xlsx", FileMode.Create))
{
    byte[] byData = package.GetAsByteArray();
    aFile.Seek(0, SeekOrigin.Begin);
    package.SaveAs(aFile);
    //aFile.Write(byData, 0, byData.Length);
    aFile.Close();
}

But Get the following error?

Package object was closed and disposed, so cannot carry out operations on this object or any stream opened on a part of this package.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:55:00+00:00Added an answer on June 14, 2026 at 8:55 am

    The package will be closed & disposed after you call any of functions GetAsByteArray, Save, SaveAs. That is the reason why you got message

    Package object was closed and disposed, so cannot carry out operations on this object or any stream opened on a part of this package.

    The solution is that after the saving you call Load function to continue processing on excel file. Or if you just want to get both ByteArray & FileOutput, I’m sure with you they both are same.

    You can read data after have saved file to the disk:

    string path = @"C:\test1.xlsx";
    Stream stream = File.Create(path);
    package.SaveAs(stream);
    stream.Close();
    
    byte[] data = File.ReadAllBytes(path);
    

    Or you can save data to disk after get the ByteArray:

    byte[] data = package.GetAsByteArray();
    
    string path = @"C:\test1.xlsx";
    File.WriteAllBytes(path, data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to use the subset.ff function in the ff package? Here
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know how to use BRR weights in Lumley's survey package for estimating
Does anyone know anyway to use something similar to polygon.getKml() except for the current
Does anyone know how to use an icon instead of text for the UINavigationController
Does anyone know how to use the command line compiler ('cl' and 'link') in
Does anyone know how to use different provider for membership? Actually i want to
I know I can use Request.Browser.IsMobileDevice . But does anyone know how it works,
Does anyone know of a method to use CRTP to count the number of
Does anyone know the syntax to use to add pattern styles to the cell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.