Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can anyone please explain this code
C#
if (e.CommandName == "download")
            {
                string filename = e.CommandArgument.ToString();
                string path = MapPath("~/Docfiles/" + filename);
                byte[] bts = System.IO.File.ReadAllBytes(path);
                Response.Clear();
                Response.ClearHeaders();
                Response.AddHeader("Content-Type", "Application/octet-stream");
                Response.AddHeader("Content-Length", bts.Length.ToString());
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.BinaryWrite(bts);
                Response.Flush();
                Response.End();
            }



what is command argument, mappath, and also what is this
"Content-Type", "Application/octet-stream"
and also
C#
Response.AddHeader("Content-Length", bts.Length.ToString());
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.BinaryWrite(bts);
                Response.Flush();
Posted

1 solution

e.CommandName is a command argument, which is associated with any control i.e Button, ImageButton etc.
In addition, you would find CommandName property for these controls while writing the code. So it is nothing but the message(argument) that gets executed when control is clicked.

And about the "Content-Type", "Application/octet-stream" , this is the MIME - Multipurpose Internet Mail Extensions, is an internet standard that is used to describe the contents of various files.
You can see plenty of extension over here[^] with its file type.

-KR
 
Share this answer
 

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