Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon May 19, 2014 12:16 pm

Trying to follow the tutorial for sending to browser. The line below doesn't seem to be working.

Code: Select all
//To open this pdf document in client browser.
newDoc.SaveToHttpResponse("sample.pdf",HttpContext.Current.Response, HttpReadType.Open);


The 2nd argument (HttpContext.Current.Response) - there is no definition for "Current" in HttpContextBase. What is the correct argument to use here?

I am working around it now by saving a temp PDF file to a drive, then opening that temp file - but I'd rather do everything in memory.

rbowser
 
Posts: 5
Joined: Mon May 19, 2014 11:58 am

Mon May 19, 2014 3:14 pm

Figured out my problem.

Code: Select all
Stream ms = new MemoryStream();

HttpContext context = System.Web.HttpContext.Current;

newDoc.SaveToHttpResponse(ms, context);

rbowser
 
Posts: 5
Joined: Mon May 19, 2014 11:58 am

Tue May 20, 2014 2:48 am

Hello,

Thanks for your interest in our component.
Please feel free to contact us if you have further problems.

Have a nice day.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Feb 24, 2023 5:00 am

book.SaveToHttpResponse("D:\Cronus\CompareASMTRvsSCCM.xlsx", response:=, httpContextType:=True, fileFormat:=FileFormat.Xlsb2010)

what must I fill after "response:=" ?

Thanks

peterocta
 
Posts: 4
Joined: Fri Feb 24, 2023 4:59 am

Fri Feb 24, 2023 6:06 am

Hello,

Thanks for your inquiry.
Yes, you need to set HttpResponse object to "response". Please notice that the effect of the method of SaveToHttpResponse() is that return the generated excel document to the browser, the complete code of SaveToHttpResponse() is following:
Code: Select all
public void SaveToHttpResponse(string FileName, HttpResponse response, HttpContentType httpContextType, FileFormat fileFormat)
        {
………
}

If you don’t return the generated excel document to the browser, and just save the generated excel document to the local computer, you can use SaveToFile() method, the following is reference code:
Code: Select all
workbook.SaveToFile("D:\Cronus\CompareASMTRvsSCCM.xlsx", ExcelVersion.Version2010);

If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Fri Feb 24, 2023 6:13 am

I need to show pop up dialog so user can choose folder to save.

Can you give me the example complete code of using book.SaveToHttpResponse

Thank you

peterocta
 
Posts: 4
Joined: Fri Feb 24, 2023 4:59 am

Fri Feb 24, 2023 6:38 am

Hello,

Thanks for your feedback.
For your scenario, I suggest you can save the file to stream then output the stream to client browser. I attached the reference code below.
Code: Select all
 Stream stream= new MemoryStream();
            workbook.SaveToStream(stream,FileFormat.Version2010);


If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Mon Feb 27, 2023 5:00 am

Can you give me the complete example code of using book.SaveToHttpResponse
I just need to use SaveToHTTPResponse.
Thank you

peterocta
 
Posts: 4
Joined: Fri Feb 24, 2023 4:59 am

Mon Feb 27, 2023 6:44 am

Hello,

Thanks for your feedback.
Please refer to the following code:

Code: Select all
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;

            workbook.SaveToHttpResponse("/test.xlsx", Response,HttpContentType.Excel2010,FileFormat.Xlsb2010);

If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Mon Feb 27, 2023 8:40 am

Did that code can run in Visual Studio 2019 (Visual Basic) ?
Thanks

peterocta
 
Posts: 4
Joined: Fri Feb 24, 2023 4:59 am

Wed Mar 01, 2023 1:38 am

Hello,

Thanks for your inquiry.
Yes, the relevant VB code is following:
Code: Select all
   Dim htttpResponse As HttpResponse = HttpContext.Current.Response
        workbook.SaveToHttpResponse("/test.xlsx", Response, HttpContentType.Excel2010, FileFormat.Xlsb2010)

If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF