Hi,
I'm getting this error when trying package.save()
When should I try save or saveAs(this.FileStream)
It doesn't work either way
protected void preProcessCatalogMaintenanceRequestXML() { System.Exception ex; try { CatVendorDateTime uploadDateTime = CatVendorCatalogMaintenanceRequest::findRecId(catVendorCatalogMaintenanceRecId).UploadDateTime; using(ExcelPackage package = new ExcelPackage(this.fileStream)) { int rowCount,columnCount, rowIterator, columnIterator; package.Load(this.fileStream); ExcelWorksheet worksheet = package.get_workbook().get_worksheets().get_Item(1); OfficeOpenXml.ExcelRange range = worksheet.Cells; rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row 1; columnCount = worksheet.Dimension.End.Column - worksheet.Dimension.Start.Column 1; package.Save(); fileId = this.uploadFileToTempStorage(this.fileStream, fullFileName); } } } catch(ex) { info(ex.Message); } }
Good, it's great th problem is resolved. It's just a pity that you didn't do it already when I suggested it (in another thread).
Your problem about entity mapping doesn't belong to this thread (which is about "Specified cast is not valid"). Create a new thread with an appropriate title title and explain your problem there. Tell us how you created or updated the entity (something wasn't done correctly there) and if you're able to import the same file through data management.
Hi Martin,
I replaced line 31 with setValue(datetime2str(uploadDateTime)) and it stopped erroring at save package. It seems it needs to be string.
However the import is failing on the execution details of the entity. Saying "input column specified was not found in the entity mapping(input column UPLOADATETIME was not found in the input column collection)".. Does that mean the code to save to the excel file is not working? What's wrong with it?
Hi Martin,
This.FileStream is of type System.IO.Stream
And when I debug it, it's system.IO.Memory
And the capacity, Length and Position are filled (not zero)
I tried to replace package.Save()
With those lines:
Using(System.IO.MemoryStream output stream = new System.IO.MemoryStream())
{
Package.SaveAs(outputStream);
FileId=this.uploadFileToTempStorage(this.filestream, fullFileName);
}
But same error...may I know why I should use saveAs and use new stream?
Note I only have one row after the header in my example
What object do you have in fileStream variable?
Is it the full message? Doesn't it mention it the actual types? Isn't it actually related to your utcDateTime field? Won't the problem disappear if you remove the assignment at line 31? If so, you're now discussion the same thing in four threads under two user accounts...
Also, the whole idea to using SaveAs() to save to the original package looks suspicious at least. If you want to use SaveAs(), let me remind you once more (I already did it in another thread) that I already showed you sample code. Please look at it, try it and let us know if it works for you. It saves the result to a MemoryStream object.
By the way, you claimed in another thread that the value should be unique, but you're trying to set the same value to all rows.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156