.NETGURU
Automatically Start Download
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Gavin
Hi All,

I think this is a simple question really.
I have an application that exports my crystal reports to .pdf and saves them
on my server, what I would like to do now is to begin an automatic download
of this file to the client but can't seem to get that to work.

If I just point the clients browser at the file then it just opens it, I
don't want this I want it to come up and ask them where they wish to save
it.

I hope this is a simple answer :).

Thanks,
Gavin

Reply to this message...
 
    
Tim
This works fine for me:

try
{
String FileName =3D SavePDF();
Response.Clear();
    Response.Buffer =3D true;
    // if export to PDF
    if (ExportList.SelectedIndex =3D=3D 0)
    {
        Response.AddHeader("Content-Type","application/pdf");
        Response.AddHeader("Content-Disposition","attachment;filename=3D" + =
"orderlist.pdf" + ";");
    }
    // else export to Excel
    else
    {
        Response.AddHeader("Content-Type","application/xls");
        Response.AddHeader("Content-Disposition","attachment;filename=3D" + =
"orderlist.xls" + ";");
    }
    FileStream Fs =3D new FileStream(FileName,FileMode.Open);
    long FileSize =3D Fs.Length;
    byte[] bBuffer =3D new Byte[FileSize];
    Fs.Read(bBuffer,0,Convert.ToInt32(FileSize));
    Fs.Close();

    Response.BinaryWrite(bBuffer);
    Response.Flush();
    Response.Close();
}

If you are using PDF, you should only watch the first case: =
Response.AddHeader("Content-Type","application/pdf");

Best Regards,
Tim Musschoot
AspFriends Moderation Team

----- Original Message -----
From: Gavin <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Fri, 16 Aug 2002 10:15:46 +0100
Subject: Automatically Start Download
[Original message clipped]

Reply to this message...
 
    
Gavin
Thanks a million, that works perfectly.

I'm glad it wasn't totally obvious, I don't feel that dumb anymore..

Cheers,
Gavin

[Original message clipped]

Reply to this message...
 
 
System.Byte
System.Convert
System.IO.FileMode
System.IO.FileStream




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification