getworkbook byte array

I am not sure if this question belongs here. Please advice where should it be posted if not here.

I have written the following lines of code in my web app using excel services api.

wbname=filename.xlsx;

ES.Status[] status;

xlService.Timeout = 1200000;

string sessionId =null;

xlService.Credentials = System.Net.CredentialCache.DefaultCredentials;

sessionId = xlService.OpenWorkbook(invworkbookLoc,"en-US","en-US",out status);

status = xlService.SetCellA1(sessionId,"sheetname","namerange", somevalue);

xlService.CalculateWorkbook(sessionId,CalculateType.Recalculate);

workbook = xlService.GetWorkbook(sessionId,WorkbookType.PublishedItemsSnapshot,out status);

status = xlService.CloseWorkbook(sessionId);

Response.Clear();

Response.AppendHeader("Content-Disposition","attachment;filename=" + wbname);

Response.Charset ="";

Response.ContentType ="application/x.ms-excel";

BinaryWriter binaryWriter =newBinaryWriter(Response.OutputStream);

binaryWriter.Write(workbook);

This opens up the open/save dialog box when i choose either, the excel 2007 client pops up the information window with "Excel found unreadable content in 'wbname'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

When I select yes, the client opens the workbook with the operation "open and repair wbname" and pops the message "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded" at the end and file name is called "wbname[repaired].xlsx".

There is no error when I create a sharepoint folder object and add the file to sharepoint library using

SPWeb site =SPControl.GetContextWeb(this.Context);

site.Files.Add(excelfilepath, workbook,true);

site.Files.Folder.Update();

hyperlink.navigateURL = excelfilepath;

I can download the excel file in excelfilepath without any error.

what setting am i missing here?

Thanks for your time.

[3743 byte] By [manasig] at [2008-1-7]
# 1

The Content-Type header is set incorrectly. It needs to be either:

For XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

For XLSX: "application/vnd.ms-excel.sheet.binary.macroEnabled.12";

See if this resolves the issue for you.

IraLevin at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...
# 3

Thank you very much that was very helpful

manasig at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...
# 4

I have added Response.end() to the end of above code.I have the code enclosed in try catch block and I see the thread exception you are talking about. But what ever I do with it, my page stops responding after getting the dialog box pop-up. I have to refresh the page from the browser refresh button for the controls to work again. I guess Response.End () has a problem where it aborts page execution. All the workarounds put the corrupt file error back to the application.

manasig at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...
# 5

I dont know ASP.NET that well, but I can try helping.

How do you create the link that returns the byte-array? Is it a postack to the same ASP.NET page?

Also, are you using cookies? The AJAX Library?

ShaharPrish-MSFT at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...
# 6

I am using a regular button click event in a asp page, and in code behind for button click event i have the code i have posted here. I know this is not a sharepoint or excel service thing and being new to asp myself, i am trying to find a work around. This link has some information, http://support.microsoft.com/kb/312629.

I am actually doing the same thing you have in your blog here

http://blogs.msdn.com/cumgranosalis/archive/2007/08/21/ewa-companion-part-3-open-download-functionality.aspx

I am trying to do what you do in your render override in a simple button click event.

It is a post back to the same page and i am not setting any special cookies or variables. i am getting the user credentials(encrypted) from a loginpage in query string for this page.I am not using ajax library

By the way thank you for all those awsome ideas in those blogs to manipulate sharepoint

manasig at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...
# 7

I noticed you are rendering the file in a new page and so it does not affect the current page. I will try to do something similar. Thanks for the help

manasig at 2007-10-2 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Excel Services...

SharePoint Products and Technologies

Site Classified