This project has moved and is read-only. For the latest updates, please go here.

ExcelPackage Constructor hangs in Event Reciever

Aug 10, 2012 at 6:19 PM
Edited Aug 10, 2012 at 6:27 PM

I am simply trying to get values from an excel spreadsheet uploaded to a document library in Sharepoint. I have placed the code in an event receiver similar to this link :

http://blogs.msdn.com/b/pranab/archive/2009/05/14/how-to-publish-ms-excel-cell-values-in-metadata-columns-as-in-quickparts-for-ms-word.aspx

 

Everything works properly until using (ExcelPackage ep = new ExcelPackage() ). The sublist "testthis" is never populated and the event receiver hangs. I checked to make sure the openBinaryFile method is returning a non empty byte array and also that the memory stream is populated. Again, everything works until that using declaration.

 

public override void ItemAdded(SPItemEventProperties properties)
        {
            SPDocumentLibrary someLibrary;
            base.ItemAdding(properties);
            web = properties.OpenWeb();
            if (web.Lists[properties.ListTitle] is SPDocumentLibrary)
            {
                someLibrary = (SPDocumentLibrary)web.Lists[properties.ListTitle];
            }


            if (properties.ListItem.File != null)
            {
                SPListItemCollection table = web.Lists["testthis"].Items;
                SPListItem newRow = table.Add();
                
                
                
                MemoryStream fs = new MemoryStream();
                fs.Write(properties.ListItem.File.OpenBinary(), 0, Convert.ToInt32(properties.ListItem.File.TotalLength));

                using (ExcelPackage ep = new ExcelPackage())
                {

                }


		newRow["Title"] = "test";


                fs.Close();
                newRow.Update();


            }