Click here to Skip to main content
16,016,477 members
Home / Discussions / Web Development
   

Web Development

 
AnswerRe: Perl and C++ Pin
A.A.5-Jul-06 3:04
A.A.5-Jul-06 3:04 
QuestionAJAX:Read XMLHttpRequest.responseText or responseXML while readysate==3 Pin
e11even30-Jun-06 13:04
e11even30-Jun-06 13:04 
AnswerRe: AJAX:Read XMLHttpRequest.responseText or responseXML while readysate==3 Pin
Shog930-Jun-06 15:48
sitebuilderShog930-Jun-06 15:48 
QuestionFile download without redirecting Pin
saqib_saeed30-Jun-06 6:21
saqib_saeed30-Jun-06 6:21 
AnswerRe: File download without redirecting Pin
Axel Seitz30-Jun-06 15:15
Axel Seitz30-Jun-06 15:15 
AnswerRe: File download without redirecting Pin
Shog91-Jul-06 7:06
sitebuilderShog91-Jul-06 7:06 
AnswerRe: File download without redirecting Pin
saqib_saeed2-Jul-06 5:09
saqib_saeed2-Jul-06 5:09 
AnswerRe: File download without redirecting Pin
Edbert P2-Jul-06 15:36
Edbert P2-Jul-06 15:36 
I have the following script that you might want to use.
If you call the script on the postback of a page, it will not redirect to a blank page.
Sorry I don't have time right now to explain it. If you need further information just notify me.

public void ServeFile(bool download, string fileLocation, string originalFileName, string fileType, ref System.Web.UI.Page currentPage)
        {
            System.IO.Stream iStream;
            long dataToRead;
            int length;
            byte[] buffer = new Byte[10000];
            try
            {
                iStream = new System.IO.FileStream(fileLocation, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                dataToRead = iStream.Length;

                currentPage.Response.Clear();
                if (download)
                {
                    currentPage.Response.AddHeader("Content-Disposition", String.Concat("attachment; filename=", originalFileName));
                    currentPage.Response.ContentType = "application/octet-stream";
                }
                else
                {
                    currentPage.Response.AddHeader("Content-Disposition", String.Concat("filename=", originalFileName));
                    currentPage.Response.ContentType = fileType;
                }
                currentPage.Response.AddHeader("Content-Length", iStream.Length.ToString());

                while (dataToRead > 0)
                {
                    if (currentPage.Response.IsClientConnected)
                    {
                        length = iStream.Read(buffer, 0, 10000);

                        currentPage.Response.OutputStream.Write(buffer, 0, length);
                        currentPage.Response.Flush();

                        buffer = new Byte[10000];
                        dataToRead = dataToRead - length;
                    }
                    else
                        dataToRead = -1;

                }
                //currentPage.Response.End();
            }
            catch (Exception e)
            {
                throw new ApplicationException("An unexpected error occured while serving file " + originalFileName, e);
            }


"Democracy is two wolves and a sheep voting on what to have for dinner" - Ross

Edbert
Sydney, Australia
QuestionNEED HELP! - Simple string manipulation Pin
VK-Cadec30-Jun-06 5:50
VK-Cadec30-Jun-06 5:50 
AnswerRe: NEED HELP! - Simple string manipulation Pin
Guffa1-Jul-06 4:03
Guffa1-Jul-06 4:03 
GeneralRe: NEED HELP! - Simple string manipulation Pin
VK-Cadec3-Jul-06 3:44
VK-Cadec3-Jul-06 3:44 
GeneralRe: NEED HELP! - Simple string manipulation Pin
RichardGrimmer4-Jul-06 1:18
RichardGrimmer4-Jul-06 1:18 
QuestionBinaryWrite and the "Action canceled" page Pin
Chris Losinger30-Jun-06 5:31
professionalChris Losinger30-Jun-06 5:31 
AnswerRe: BinaryWrite and the "Action canceled" page Pin
Shog930-Jun-06 15:56
sitebuilderShog930-Jun-06 15:56 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Chris Losinger30-Jun-06 20:15
professionalChris Losinger30-Jun-06 20:15 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Shog91-Jul-06 5:48
sitebuilderShog91-Jul-06 5:48 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Chris Losinger1-Jul-06 6:37
professionalChris Losinger1-Jul-06 6:37 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Shog91-Jul-06 6:59
sitebuilderShog91-Jul-06 6:59 
GeneralRe: BinaryWrite and the "Action canceled" page [modified] Pin
Chris Losinger1-Jul-06 7:11
professionalChris Losinger1-Jul-06 7:11 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Shog91-Jul-06 7:37
sitebuilderShog91-Jul-06 7:37 
AnswerRe: BinaryWrite and the "Action canceled" page Pin
Edbert P2-Jul-06 15:33
Edbert P2-Jul-06 15:33 
GeneralRe: BinaryWrite and the "Action canceled" page Pin
Chris Losinger2-Jul-06 16:10
professionalChris Losinger2-Jul-06 16:10 
QuestionHow to retrieve data stored on a different server... Pin
aspwizkid29-Jun-06 20:46
aspwizkid29-Jun-06 20:46 
QuestionBeginner Question about Firefox Controls Pin
Richard Andrew x6429-Jun-06 9:26
professionalRichard Andrew x6429-Jun-06 9:26 
QuestionOpening new windows from ASP Pin
mjackson1129-Jun-06 8:29
mjackson1129-Jun-06 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.