zoukankan      html  css  js  c++  java
  • 从WebResponse获取源文件名、扩展名

            static string GetFilenameFromResponse(WebResponse wr, string defaultFilename)
            {

                string desc = wr.Headers["Content-Disposition"];

                if (desc != null)
                {
                    string fstr = "filename=";
                    int pos1 = desc.IndexOf(fstr);
                    if (pos1 > 0)
                    {
                        string fn = desc.Substring(pos1 + fstr.Length);
                        if (fn != "")
                            defaultFilename = System.Environment.CurrentDirectory + "\\" + fn;

                    }


                }
                return defaultFilename;
            }

            static string GetExtensionFromResponse(WebResponse wr,string defaultExt)
            {
                Hashtable htmimes = new Hashtable();
                htmimes["image/jpeg"] = ".jpg";
                htmimes["image/png"] = ".png";
                htmimes["image/tiff"] = ".tif";
                htmimes["image/bmp"] = ".bmp";
                htmimes["image/gif"] = ".gif";

                string ct = wr.ContentType;
                if (ct != null)
                {
                    if (htmimes.ContainsKey(ct)) defaultExt = htmimes[ct].ToString();
                }
                return defaultExt;
            }

  • 相关阅读:
    java进度条
    获取程序运行环境
    struts2学习笔记(二) 初识Struts2
    HttpComponents入门解析
    C#编码规范
    js实现GBK编码
    struts2学习笔记(一) MVC模式
    mysql数据库操作类
    java类装载器原理
    [Study Note] NHibernate in Action 20100729
  • 原文地址:https://www.cnblogs.com/dashi/p/4034752.html
Copyright © 2011-2022 走看看