Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends.

I'm using the following code in my app to download a .wav file.
This all code is on MySpace.aspx page. When Request made on this page a method works there getData(); which simply fetch the records.

There are Three other methods

1. trackCount() == this checks the count only
2. MessageRead() == this marks the flag as R in the database;
3. getData() == this fetch the records and check if flag is U then change the row color in Gridview.

In the code I have used
C#
Response.Redirect("MySpace.aspx?val=Inbox", false);
What I want to do simply download the file if download done the flag updated to R and getData() method to call so that the color of row in gridview changes as per the flag.

But if I use getData(); then it doesn't reload after the file downloaded.
And If I make
C#
Response.Redirect("MySpace.aspx?val=Inbox", false);
then gridview reloaded and row color changes but file doesn't get downalod.

Please suggest me how can I accomplish this. Basically I want to call getData() method after Response.Write() method.
I removed Response.End() because this was terminating the Request and as I require I have to call some other methods after downloading the file.

Following is the Code.
C#
Response.AddHeader("content-disposition", "attachment; filename=" + info.Name);
Response.AddHeader("content-length", info.Length.ToString());
Response.ContentType = "audio/x-wav";
Response.WriteFile(info.FullName);
doflag = true;
if (doflag)
{
trackCount("INSERT INTO TrackUserAction(Phnum,trackdownload) VALUES('" + Session["phnum"].ToString() + "',1)", "in");
                           MessageRead(((Label)gvMyDetails.Rows[index].FindControl("lblSender")).Text.Trim(),((Label)gvMyDetails.Rows[index].FindControl("lblMsgTime")).Text.Trim(), msgID);
Response.Redirect("MySpace.aspx?val=Inbox", false);
}



Thanks and Regards
Posted
Updated 29-Sep-11 21:39pm
v3

 
Share this answer
 
Comments
Manish Kumar Namdev 30-Sep-11 3:34am    
Thanks to reply, but this not what I'm looking

I want to call some other methods after downloading the files
 
Share this answer
 
v2
Hi, Manish

If u are try to download a file from ur local server or from webserver
u need to convert the file into byte and than try to read that

Here the sample Code:

C#
Public Void DownloadFile(string Path)
{
 long FileSize;
 FileInfo fileName = new FileInfo(path);
 Response.ContentType = "audio/x-wav";
 Response.AddHeader("content-disposition", "attachment; filename=" +                        fileName.Name);
 FileStream sourceFile = new FileStream(path, FileMode.Open);
 FileSize = sourceFile.Length;
 byte[] getContent = new byte[(int)FileSize];
 sourceFile.Read(getContent, 0, (int)sourceFile.Length);
 sourceFile.Close();
 Response.BinaryWrite(getContent);
 //Response.Flush();
 //Response.Close();
 Response.End();
}


If Response.End() throws an exception than use Commented Code.
Here u need to pass the path to this method than it will download.

Hope it will help u....

Sabbi..
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900