15,912,578 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Indhu S 2021 (Top 6 by date)
Indhu S 2021
10-Aug-21 4:26am
View
Hi Richard, Unfortunately I was not able to share the Jquery as it is from Sitecore side and it has licensing issues. But you gave me an great hint about XMLHttpRequest, let me check further on this one. Thank you so much for all the prompt and highly helpful responses.
Indhu S 2021
8-Aug-21 8:22am
View
Hi Richard, Thanks for the comment.
Posting the request and response headers below. Have marked some values as "XXXXX". It is not an ajax call, but I am actually trying to download a pdf on the custom submit action of the Sitecore Forms module.
One error I used to get is that ,
"System.Web.HttpException: 'Server cannot append header after HTTP headers have been sent."
in the @Html.AntiForgeryToken() line of Forms.cshtml.
Response Headers:
cache-control: private
content-disposition: attachment; filename="MyFile.pdf"
content-type: application/pdf
date: Fri, 06 Aug 2021 14:21:15 GMT
server: Microsoft-IIS/10.0
Request headers:
:authority: XXXXXXXXXX.sc.XXXXXXXX-intra.com
:method: POST
:path: /formbuilder?fxb.FormItemId=XXXXXXXXXXXXX&fxb.HtmlPrefix=fxb.XXXXXXXXXXXXXX
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en,en-US;q=0.9,ar;q=0.8
content-length: 3342
content-type: application/x-www-form-urlencoded; charset=UTF-8
cookie: XXXXXXXXXXXXXRoleCookie=XXXXXXXXXX; OptanonAlertBoxClosed=2021-07-27T12:49:52.228Z;
_gcl_au=XXXXXXXXXXXXXXXX;
_ga=XXXXXXXXXXXXXXX; Disclaimer_cookie=true;
SC_ANALYTICS_GLOBAL_COOKIE=7XXXXXXXXXXXXXXX|True;
ASP.NET_SessionId=XXXXXXXXXXXXXXXXX;
FormsAuthKey=1;
__RequestVerificationToken=VXXXXXXXXXXXXXXXXXxx;
_gid=XXXXXXXXXXXXXXXXX;
OptanonConsent=isGpcEnabled=0&datestamp=Fri+Aug+06+2021+12%3A53%3A19+GMT%2B0530+(India+Standard+Time)
&version=6.20.0&isIGlobal=false&hosts=&consentId=XXXXXXXXXXXXXxx&
interactionCount=1&landingPath=NotLandingPage
&groups=1%3A1%2C2%3A1%2C3%3A1%2C4%3A1&
geolocation=%3B&AwaitingReconsent=false;
countryXX#lang=en
origin: https://XXXXX.sc.XXXXXXX-intra.com
referer: https://XXXXXXXX.sc.XXXXXXXX-intra.com/en/testformspdf
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
x-requested-with: XMLHttpRequest
Indhu S 2021
5-Aug-21 9:45am
View
Yes. I am able to view other PDF's perfectly in browser. Thank you so much Richard for constant responses. I highly appreciate that and hearty thanks for the same. I just wanted to know whether these are the only steps(or code) to download a PDF.
If that is right, there is certainly something else I should check these with overall project structure(some headers/classes or something else from other calls) affecting this.
Indhu S 2021
5-Aug-21 2:01am
View
Thanks again for your response. Yes, I tried that already and could see the same behavior across all browser(Chrome/Firefox and Edge) :(
Indhu S 2021
4-Aug-21 11:52am
View
Thanks for the response Richard!
I am seeing the response headers as given below in network tab though. So really not sure what is going wrong.
cache-control: private
content-disposition: attachment; filename="MyFile.pdf"
content-type: application/pdf
date: Wed, 04 Aug 2021 15:40:19 GMT
server: Microsoft-IIS/10.0
Indhu S 2021
3-Aug-21 10:29am
View
Thanks much for the response. Sorry for the confusion, the first block I just tried to see whether it is at least getting saved in file system. Also I unnecessarily converting the types back and forth.
Leaving that part, I tried to directly write the byte array by following your code
var response = HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/pdf";
response.AppendHeader("Content-Disposition", "attachment; filename=\"MyFile.pdf\"");
response.OutputStream.Write(pdfFile, 0, pdfFile.Length);
response.End();
But my browser output is still the same. I also tried with response.BinaryWrite(pdfFile) but no luck..
Can you share some light?
Show More