views:

15

answers:

1

how to force download dialog for a text file on the server?

when i used the blow code so the dialog window was for aspx file ... (why?)

    string FileBankPhysicalFolder = Server.MapPath("~/FileBanks/");
    string Name = "FileBank_" + "Melli_" + Session["Co_ID"].ToString() + "_" + RadcbDateOfPardakht.SelectedValue.Replace('/',',') + ".txt";
    string FileBankPath = FileBankPhysicalFolder + Name;
    string Content = Header + Body;
    System.IO.File.WriteAllText(FileBankPath, Content);

    Response.ContentType = "text/plain";
    Response.AppendHeader("Content-Disposition", "attachment;" +  Name);
    Response.WriteFile(FileBankPath);
    Response.End();

how can i fix this problem?

A: 

You should send force-download headers along with the file. I don't know how you would do that in ASP but basically you have to read the file with some ASP built-in function then output it to the browser attaching

Content-Type: application/force-download;
Content-Disposition: attachment; filename=\yourfile.txt

Judging by your code:

Response.AppendHeader("Content-Type", "application/force-download;");
Response.AppendHeader("Content-Disposition", "attachment; filename="+ Name);

Cheers!

Claudiu
thanks a lot...
LostLord
You're welcome buddy :)
Claudiu