Music file down load using linkbutton how ?

Posted by Chandru_ra under C# on 3/29/2011 | Points: 10 | Views : 1181 | Status : [Member] | Replies : 1
hi

now am file downloading concept

protected void LinkButton1_Click(object sender, EventArgs e)
{
string FilePath = Server.MapPath(Request.QueryString["MusicUpload"].ToString());
System.IO.FileInfo TargetFile = new System.IO.FileInfo(FilePath);
if (TargetFile.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + TargetFile.Name);
Response.AddHeader("Content-Length", TargetFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(TargetFile.FullName);
}

but this coding client side perfect but not support server side...
i want server support coding..

chandru


Responses

Posted by: Pavanandey on: 3/29/2011 [Member] Bronze | Points: 25

Up
0
Down
String FILENAME = Server.MapPath(Request.QueryString["MusicUpload"].ToString());
string ST = ReverseString(FILENAME);
int i = ST.IndexOf(".");
ST = ST.Substring(0, i);
Response.ContentType = "document/" + ReverseString(ST);
String Header = "Attachment;Filename=" + doc extension;
Response.AppendHeader("Content-Disposition", Header);
System.IO.FileInfo Dfile = new System.IO.FileInfo(FILENAME);
Response.WriteFile(Dfile.FullName);
Response.End();

Thanks
Pavan Kumar
Mark Answer if this fits the need

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response