File Download pop-up window for excel - export-to-excel

Hi
I have written a procedure called 'ExportDataTableToExcel(dataTable)', which accepts a data table and displays all data into an excel worksheet. However, it doesn't display the 'File Download' pop-up window with Open/Save/Cancel options before displaying the excel worksheet.
Any help with required code will be much appreciated. I am using ASP.NET application.
Thanks

we do it in Java, but it should work similarly also with ASP.NET
Setting the "Content-Disposition" header should help, if not working try also to set the content type as "application/unknown"
Java Code:
response.setHeader( "Content-Disposition", "attachment; filename=\"" + fileName + "\"" );
// If it doesn't work with the line above, add also this one
response.setContentType( "application/unknown" );

Related

Content-Disposition inline filename issue with IE

I am displaying a pdf in browser with inline from API using an aspx page.
While saving the pdf using Chrome/Firefox, takes the filename from header("Content-Disposition", "inline;filename=xyz.pdf")
But while saving the pdf using IE it does not reads the filename from header("Content-Disposition", "inline;filename=xyz.pdf"). instead it takes the aspx name.
Technical details
I have an xyz.aspx page.
The xyz.aspx page will invoke an API for a document.
Then the downloaded document from API will transferred to browser with inline to display the pdf document.
Am setting the response header as below and writing the file bytes.
HttpContext.Current.Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "inline;filename=\"" + Name + "\"");
HttpContext.Current.Response.ContentType = "application/pdf";
Issue:
While saving the opened pdf in IE it takes xyz.aspx instead of the name from header.
Requirement:
While saving the pdf using IE, it need to save with the name of pdf.
I googled so much, as every one tells its IE behavior. I hope some one knows a solution.
Note: I have to display the pdf in browser and then save. Not to download using "attachment"
It is true some versions of IE can't handle ("Content-Disposition", "inline;filename=...")
This is because filename=... was originally intended for the attachment disposition. Not all browser-based PDF viewers can handle it.
The only solution I see is to allow access via a different url.
Suppose you have a route to the pdf like: /pdf/view. If you change it to /pdf/view/filename and you configure your application to handle this route in the same way as /pdf/view your problem is solved.
You can also re-write the download url on the webserver.
Depending on your webserver you have various ways of doing this.
I have also tried with all kind of headers and methods.
In the end, my solution was
private FileResult ReturnStreamAsPdf(string fileName, Stream stream)
{
ContentDisposition cd = new ContentDisposition
{
FileName = fileName,
Inline = true // false = prompt the user for downloading; true = browser to try to show the file inline
};
Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("X-Content-Type-Options", "nosniff");
return new FileStreamResult(stream, MediaTypeNames.Application.Pdf);
}
and the Route Attribute on the method:
[Route("api/getpdfticket/{ticketnumber}")]
public async Task<FileResult> GetPdfTicket(string ticketnumber)
And the href:
href="#($"/api/getpdfticket/{product.TicketNumber}.pdf")"
It seems like Microsloft is still inventing their own standards:
http://test.greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf
PDF Handler : content-disposition filename

VBS - display multple filetypes in save dialog

I got the following code to open the save dialog with one FileType:
Set objDialog = CreateObject("SAFRCFileDlg.FileSave")
objDialog.FileName = "Automatic Generated Presentation"
objDialog.FileType = "PowerPoint 97-2003 Presentation (*.ppt)"
objDialog.OpenFileSaveDlg
How can I add another FileType to the combobox / listbox in the dialog?
I tried to seperate them using '|', using ',', using ';' and more - nothing worked ofcourse.
Is that even possible?
I didnt find anything like that in the internet.
Will appreciate your help.
I've found an interesting article where the author debugs Windows API calls made by the SAFRCFileDlg.FileSave object to find out whether it allows multiple file filters:
Debugging the SAFRCDLG.DLL FileType filter string
The answer is No.

How to open and handle richtext editor in javascript in sitecore 6.5?

I've been working on a custom field, which contains a list.
I have to be able to edit the selected item on the list in a richtext editor. (this is the only missing part).
I've read the topic on opening from c# code Opening Rich Text Editor in custom field of Sitecore Content Editor .
This works nice for the "add" button, since i have to open the RTE empty(with default text...), but not for the Edit button.
My aproaches are:
Somehow in the Edit button's message field list:edit(id=$Target) pass the selected index (like list:edit(id=$Target,index=$SelectedIndex), but i don't know how to populate $SelectedIndex
Somehow in the overridden HandleMessage method get the list's selected index. I'm able to get the selected value Sitecore.Context.ClientPage.ClientRequest.Form[ID of list], but thats alone not much of a help, since i won't be able to decide which one to edit if two listitem equals.
Do the richtext editor opening and handling fully in javascript. As i saw at some script in content editor, i tried to do that, but i can't understand it clearly:
richtext editor url:
var page = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx";
some params :
var params = "?da=core&id&ed=" + id + "&vs=1&la=en&fld=" + id + "&so&di=0&hdl=H14074466&us=sitecore%5cadmin&mo";
and the part where i'm not sure:
var result = scForm.browser.showModalDialog(page + params, new Array(window), "dialogHeight:650px; dialogWidth:900px;");
This way the RTE opens as expected (i guess i could get the selected index from javascript and pass it as a parameter later). However when i click ok, i get exception from EditorPage.js saveRichText function: Cannot read property 'ownerDocument' of null. Am i missing some parameter?
Either of the three aproaches is fine for me(also i'm open for new better ones) as soon as i'm able to do it.
Thanks in advance!
Tamas
I was able to enter some javascript into the message:
list:Edit(id=$Target,index='+document.getElementById(ID of the select using $Target ).selectedIndex+')
this way i got the index in HandleMessage.
I'm waiting for better solutions now.

How to type cast webbrowsercontrolobj.document to mshtml.HTMLDocument VB6? or How to submit form loaded in webbrowser control in vb6?

Hello I am writing code in VB6 only (no VB.NET)
I have webbrowsercontrol object named webbrowser1
I have added reference of microsoft html object library in project.
I am trying this line but is giving error.
Dim doc as MSHTML.HTMLDocument
doc = DirectCast(webbrowser1.document, MSHTML.HTMLDocument)
line 2 is giving error that no method or data found at MSHTML.HTMLDocument
Please help me solving this problem.
What I want is I have one webpage having 2 (html forms) in it. I am loading that page into
webbrowser control by,
webbrowser1.navigate "url"
I have mapped event to handle html button click in webbrowser1's document.
When user clicks on this button I want to submit second form of html page.
Is there any other way to do it?
I also tried following code
'this line is working properly
'this is the code to submit first form in html page
webbrowser1.document.Forms(0).submit
but when I do
'this line is giving error though there are 2 forms available in html page
webbrowser1.document.Forms(1).submit
So ultimate goal is to submit second form of html document.
Please show me right direction.
You need to change Dim doc as MSHTML.HTMLDocument to Dim doc as MSHTML.IHTMLDocument.
Notice the IHTMLDocument has an I at the start, then try to submit the form.
Also, there is no such thing as DirectCast in VB6 - that is only a VB.NET thing.
So just do this:
Dim doc as MSHTML.IHTMLDocument
Set doc = webbrowser1.document
Now you will get intellisense on doc. :)
Let me know how it goes.
Have you tried just direct assignment?
Dim doc as MSHTML.HTMLDocument
Set doc = webbrowser1.document
VB6 doesn't really do casting, but you can access any method (early bound) by assigning it to an variable of the required type, or (late bound) by blindly using a variable of Object type.

vb6 Capture Entire Web Page

Hey all, I've been trying to find the code that allowed me to capture an entire web page using the webbrowser1 control and i believe also a picturebox or 2.. but i am not able to find the code that i used a couple months ago! I've been goodgling until I'm all googled out!
If anyone knows of the code for VB6 then please post a link to it!.
Thanks,
David
Do you mean the HTML source? If so you can add a reference to the Microsoft HTML obj Library and;
Dim doc As MSHTML.HTMLDocument
set doc = YourWebBrowserCtrl.Document
msgbox doc.documentElement.outerHTML
However this will not return the exact source as at this point its been parsed by IE. (It also won't include doc type or anything else preceding the opening <html> tag.
If you do want the source, add an internet transfer control and just call .openURL to get the full content.
Dim DrawSize As New Size(1024, 768)
Using MyBrowser As New WebBrowser
MyBrowser.ScrollBarsEnabled = False
MyBrowser.Size = DrawSize
MyBrowser.Navigate("http://www.stackoverflow.com")
While MyBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Using myBitmap As New Bitmap(DrawSize.Width, DrawSize.Height)
MyBrowser.DrawToBitmap(myBitmap, New Rectangle(New Point(0, 0), DrawSize))
myBitmap.Save("C:\test.jpeg")
End Using
End Using

Resources