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;
            }

  • 相关阅读:
    Solution 16: 树的层次遍历
    Solution 15: 树的镜像
    Solution 14: Two Sum
    Solution 13: 链表的倒数第K个节点
    Solution 10: 翻转句子中的单词
    Solution 11: 二叉树中节点的最大距离
    Solution 9: 判断序列是否为BST的后续遍历结果
    Solution 7: 判断两链表是否相交
    估算Baidu和Google的网页索引数量之比
    主元素问题
  • 原文地址:https://www.cnblogs.com/dashi/p/4034752.html
Copyright © 2011-2022 走看看