nopcommerce A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))

1.1k views Asked by At

i am working in nopcommerce solution 3.90, while importing products, from excel file i get this exception. my code is as follow

public virtual void ImportProductsFromXlsx(Stream stream)
    {
        try
        {
            #region Import business Logic
            using (var xlPackage = new ExcelPackage(stream))
            {
                //get the first worksheet in the workbook
                var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault();

                if (worksheet == null)
                    throw new NopException("No worksheet found");

                //the columns
                var properties = GetPropertiesByExcelCells<Product>
 (worksheet);

                var manager = new PropertyManager<Product>
 (properties);

                var attributProperties = new[]
.....
.....
 }
}

StackTrace:-

at OfficeOpenXml.Utils.CompoundDocument.ILockBytes.WriteAt(Int64 ulOffset, IntPtr pv, Int32 cb, UIntPtr& pcbWritten) at OfficeOpenXml.Utils.CompoundDocument.GetLockbyte(MemoryStream stream) at OfficeOpenXml.ExcelPackage.Load(Stream input, Stream output, String Password) at OfficeOpenXml.ExcelPackage.Load(Stream input) at OfficeOpenXml.ExcelPackage..ctor(Stream newStream) at Nop.Services.ExportImport.ImportManager.ImportProductsFromXlsx(Stream stream) in d:\Arsh\nop3.90\Libraries\Nop.Services\ExportImport\ImportManager.cs:line 330

Solutions That i have tried are :-

  1. Resaving the file to be uploaded using .xlsx extension.
  2. Using Memorystream object.
  3. Adding name of file like(Worksheets.Add("Worksheet Name");)
  4. Removing header text(i.e. header columns like Name, description, etc)

P.S. I am using Nopcommerce. This is inbuilt code of importing products.

2

There are 2 answers

0
Ammar On BEST ANSWER

Please try with excel 2010+ because earlier versions of excel differ in encrypt/decrypt algorithm.

You can read more about encryption/decryption here.

0
Humoyun Ochilov On

I used this code and it's work;

var ms = new MemoryStream();
await  eFile.File.OpenReadStream().CopyToAsync(ms);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
package = new ExcelPackage(ms);