2009/10/06

C# - Load Attachment

Sometimes when you load your file, the filename might include some special character. Look at the code below:

HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename=" + HttpUtility.UrlEncode(filenameArry[0], System.Text.Encoding.UTF8)));

When the system try to load the file with special character in the filename (like &, ;, etc) then there will be problem while reading it. You have to append the following to avoid the problem:

HttpUtility.UrlEncode(filename)

HttpUtility.Encode can solve the problem.

Enjoy.

No comments:

Post a Comment