下载文件后调用其他方法 [英] Calling other Methods after Downloading a file

查看:83
本文介绍了下载文件后调用其他方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友.

我正在我的应用程序中使用以下代码来下载.wav文件.
所有这些代码都在MySpace.aspx页上.当在此页面上发出请求时,有一种方法可以在其中运行getData();.只需提取记录即可.

还有其他三种方法

1. trackCount()==仅检查计数
2. MessageRead()==这会将标记在数据库中标记为R;
3. getData()==这将获取记录,并检查标志是否为U,然后在Gridview中更改行颜色.

在代码中,我使用了

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

Response.Redirect("MySpace.aspx?val=Inbox", false);

如果下载完成了将标志更新为R和getData()的方式,我想做的就是简单地下载文件进行调用,以使gridview中的行颜色根据标志而更改.

但是如果我使用getData();那么下载文件后便不会重新加载.
并且如果我进行

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

Response.Redirect("MySpace.aspx?val=Inbox", false);

,然后重新加载gridview并更改行颜色,但文件未降级.

请建议我如何才能做到这一点.基本上我想在Response.Write()方法之后调用getData()方法.
我删除了Response.End(),因为这终止了请求,并且根据需要,我必须在下载文件后调用其他方法.

以下是代码.

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.

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

推荐答案

如何下载在asp.net中具有路径的文件 [
file uploading and downloading in asp.net[^]

How to Download a file with a path in asp.net[^]

see these links.


请参考以下链接

在asp.net中上传和下载文件 [ ^ ]
Refer following link

file uploading and downloading in asp.net[^]


曼尼什

如果您尝试从您的本地服务器或Web服务器下载文件
您需要将文件转换为字节,然后尝试读取该文件

这里是示例代码:

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:

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();
}



如果Response.End()引发异常,则使用注释代码.
在这里,您需要传递此方法的路径,而不是将其下载.

希望对您有帮助....

Sabbi ..



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..


这篇关于下载文件后调用其他方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆