Click here to Skip to main content
15,891,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have make a messaging system in which user can send messages to each other, they can also send files as attachement in message(its like simple email system). I am facing an issue in firefox, if file name contains space(eg 602_Sign File for ticket.doc) in firefox it'll save with 602_Sign.doc however it should display complete name,issue is working fine on IE and chrome,below is my code for downloading file

C#
public ActionResult Download(string attFileName)
        {
            string FileName = Path.Combine(Server.MapPath("~/MessageAttachmentFiles"), attFileName);
            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(FileName)));
            response.TransmitFile(FileName);
            response.Flush();
            response.End();
            return null;

        }
Posted

Try this code:

C#
public ActionResult Download(string path)
        {
            var Dpath = path.ToString();
            int index = Dpath.LastIndexOf("/");
            string filename = Dpath.Substring(index);
             Dpath = Dpath.Remove(index) + filename;

            if (path != null)
                return File(Dpath, "all", filename);
            else return View("");
        }
 
Share this answer
 
v2
Comments
hitech_s 5-Apr-12 4:34am    
am also using the same it works fine for me

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