Ejemplo n.º 1
0
        private string SelectName(HttpResponse rpy)
        {
            ContentType type = new ContentType(rpy.ContentType);

            // Try from mime first.
            string name = type.Name;

            // Try from get string
            if (string.IsNullOrWhiteSpace(name))
            {
                if (rpy.Request != null)
                {
                    string str  = rpy.Request.RequestURI;
                    int    qpos = str.IndexOf('?');
                    if (qpos == -1)
                    {
                        int s = str.LastIndexOf('/');
                        name = str.Substring(s + 1);
                    }
                    else
                    {
                        int s = str.LastIndexOf('/', qpos);
                        name = str.Substring(s + 1, qpos - s - 1);
                    }
                }
            }

            // Generate a name if all previous atempts failed
            if (string.IsNullOrWhiteSpace(name))
            {
                name = rpy.ConnectionID.ToString() + MimeTypes.GetExt(type.MediaType);
            }

            // Try to recognize more file type using mime
            string ext = MimeTypes.GetExt(type.MediaType);

            if (!name.EndsWith(ext))
            {
                name += ext;
            }

            return(name);
        }