Click here to Skip to main content
16,016,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (e.CommandName == "Download")
{
           int archivedFileId = Convert.ToInt32(e.CommandArgument);

           var wrapper = new ArchivedFilesWrapper();
           var archivedFile = wrapper.GetArchivedFile(archivedFileId);

           Response.Clear();
           Response.ContentType = archivedFile.MimeType;
           Response.AddHeader("content-disposition", string.Format("attachment; {0}", archivedFile.Name));
           Response.BinaryWrite(archivedFile.BinaryData.ToArray());
           Response.End();
}



above function downloding .aspx type file while downloading any type file(like .pdf,.exe,.exl).
plz help. I want to download file with exact file format
Posted

1 solution

C#
public static string getContentType(string extension)
       {
           const string DEFAULT_CONTENT_TYPE = "application/unknown";
           RegistryKey regkey, fileextkey;
           string filecontenttype;
           string fileextension = extension;
           try
           {
               regkey = Registry.ClassesRoot;
               fileextkey = regkey.OpenSubKey(fileextension);
               filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString();
               fileextkey = null;
               regkey = null;
           }
           catch
           {
               filecontenttype = DEFAULT_CONTENT_TYPE;
           }
           return filecontenttype;
       }


Pass Exact contenttype like "pdf,txt,xmlns"
 
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