Esempio n. 1
0
        //根据查询的附件字符串解析附件地址
        public string[] GetAnnexAddrByAnnex(string annex)
        {
            string[] sp = null;

            if (annex.IndexOf(',') > 0)
            {
                sp = annex.Split(',');
            }
            else
            {
                sp = new string[] { annex }
            };

            for (int i = 0; i < sp.Length; i++)
            {
                string      downloadPath = "admin/Article/ArticleUploadFile/";
                FileTypeExt type         = CheckFileExt(sp[i]);
                switch (type)
                {
                case FileTypeExt.doc: downloadPath += "doc" + "/"; break;

                case FileTypeExt.img: downloadPath += "img" + "/"; break;

                case FileTypeExt.pdf: downloadPath += "pdf" + "/"; break;

                case FileTypeExt.rar: downloadPath += "rar" + "/"; break;

                default: downloadPath += "xsl" + "/"; break;
                }
                sp[i] = downloadPath + sp[i];
            }
            return(sp);
        }
Esempio n. 2
0
        /// <summary>
        /// 文件分类别保存方法
        /// </summary>
        /// <param name="type">文件类别</param>
        /// <param name="file">文件管理类</param>
        /// <param name="uploadPath">文件保存大路径</param>
        public void FileSave(FileTypeExt type, HttpPostedFile file, string uploadPath)
        {
            try
            {
                switch (type)
                {
                case FileTypeExt.doc: uploadPath += "doc" + "\\"; break;

                case FileTypeExt.img: uploadPath += "img" + "\\"; break;

                case FileTypeExt.pdf: uploadPath += "pdf" + "\\"; break;

                case FileTypeExt.rar: uploadPath += "rar" + "\\"; break;

                default: uploadPath += "xsl" + "\\"; break;
                }
                string filepath = uploadPath + file.FileName;
                //已经存在的文件就删除,然后重新上传一遍
                if (CheckFileExist(filepath))
                {
                    File.Delete(filepath);
                }
                //保存
                file.SaveAs(filepath);
            }
            catch
            {
                throw;
            }
        }