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

  • 相关阅读:
    如何设置IIS实现无扩展名重写
    正则表达式基础知识
    Literal控件用法
    ajaxPro.dll基础教程
    PetShop的系统架构设计
    SQL点滴29—错误无处不在
    javascript中的正则表达式
    为什么开发环境如此之乱
    SQL点滴文章总结
    javascript读写cookie
  • 原文地址:https://www.cnblogs.com/dashi/p/4034752.html
Copyright © 2011-2022 走看看