In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how C# is compatible with the file downloads of major browsers, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
1. Css code
Public void DownFile (string filePath, string fileName) {/ / filePath file path for example: / File/ record .xlsx / / fileName file name for example: record .xlsx (to suffix) Encoding encoding; / / declare coding string outputFileName; / / output name Debug.Assert (HttpContext.ApplicationInstance.Request.UserAgent! = null, "HttpContext.ApplicationInstance.Request.UserAgent! = null"); string browser = HttpContext.ApplicationInstance.Request.UserAgent.ToUpper () / Microsoft browser and ie filter if (browser.Contains ("MS") & & browser.Contains ("IE")) {outputFileName = HttpUtility.UrlEncode (filePath); encoding = Encoding.Default;} / / Firefox else if (browser.Contains ("FIREFOX")) {outputFileName = fileName;encoding = Encoding.GetEncoding ("GB2312");} else {outputFileName = HttpUtility.UrlEncode (fileName); encoding = Encoding.Default;} string absoluFilePath = Server.MapPath (filePath) / / get the upload file path FileStream fs = new FileStream (absoluFilePath, FileMode.Open); byte [] bytes = new byte [(int) fs.Length]; fs.Read (bytes, 0, bytes.Length); fs.Close (); / / close the stream and release the resource HttpContext.ApplicationInstance.Response.Clear (); HttpContext.ApplicationInstance.Response.Buffer = true;HttpContext.ApplicationInstance.Response.ContentEncoding = encoding;HttpContext.ApplicationInstance.Response.AddHeader ("Content-Disposition", string.Format ("attachment") Filename= {0} ", string.IsNullOrEmpty (outputFileName)? DateTime.Now.ToString ("yyyyMMddHHmmssfff"): outputFileName); Response.BinaryWrite (bytes); Response.Flush (); HttpContext.ApplicationInstance.Response.End ();}
2. Html code
Just write an a tag on the front-end HTML: such as file download
Thank you for reading this article carefully. I hope the article "how C# is compatible with the file downloads of major browsers" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 211
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.