Thursday 4 October 2012

File Download in ASP.NET

There are lots of situation, Where we have to use file Downloader in our project. But beginners don’t get proper code for  Downloading File. Using this code they can do it:

 File Download Query

 

             m_FilePath = "~/PdfProductFile/Raja.pdf";
            m_FileName = "Raja.pdf";
            string ext = Convert.ToString(Path.GetExtension(m_FileName.Trim('.')));
            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = "Raja/" + ext.Replace('.', ' ') + "";
            response.AddHeader("Content-Disposition", "attachment; filename=\"" + m_FileName + "\"");
            response.TransmitFile(m_FilePath);
            response.Flush();
            response.End();

No comments:

Post a Comment