国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#上傳文件的一個實現

2024-07-21 02:26:46
字體:
來源:轉載
供稿:網友
c#上傳文件的一個實現
using system;
using system.data;
using system.data.sqlclient;
using ca.components;        //全部在組件名稱空間下

namespace ca.components
{
    /// <summary>
    /// general 的摘要說明。
    /// 發布日期:2002-8-8 原作者:雷神
    /// 此程序屬模式小組 http://www.ai361.com/project/
    /// 在sql2000,win2000s+.net+iis5中測試通過
    /// </summary>
    public class general
    {
        private string filepath; //文件路徑

        //定義一個枚舉用來存放文件的信息        
        public enum file
        {
            file_size ,        //大小
            file_postname,    //
            file_sysname ,
            file_orginname,
            file_path
        };
        //構造函數
        public general()
        {
            //在web.config中設定appsettings["filepath"],用于存放文件的路徑。
            filepath = system.configuration.configurationsettings.appsettings["filepath"];
        }

        /// <summary>
        /// 上傳文件通用函數,此方法為靜態,系統任何時候均可調用。
        /// </summary>
        /// <param name="file">參數為頁面的file控件對象</param>
        /// <returns></returns>
        public static string[] uploadfile(htmlinputfile file)
        {
            string[] arr = new string[5];
            //通過系統時間生成文件名,此功能可以封閉掉,不過中文長文件名支持的不好。
            string filename = datetime.now.tostring().replace(" ","").replace(":","").replace("-","");
            string fileorginname = file.postedfile.filename.substring(file.postedfile.filename.lastindexof("http://")+1);
            if(file.postedfile.contentlength<=0)
                return null;
            string  postfilename;
            string path = new general().filepath+"http://";
            try
            {
                int pos = file.postedfile.filename.lastindexof(".")+1;
                postfilename = file.postedfile.filename.substring(pos,file.postedfile.filename.length-pos);
                file.postedfile.saveas(path+filename+"."+postfilename);
            }
            catch(exception exec)
            {
                throw(exec);
            }
  
            double unit = 1024;
            double size =  math.round(file.postedfile.contentlength/unit,2);
            arr[(int)file.file_size] = size.tostring();//文件大小
            arr[(int)file.file_postname] = postfilename;//文件類型(文件后綴名)
            arr[(int)file.file_sysname] = filename;//文件系統名
            arr[(int)file.file_orginname] = fileorginname;//文件原來的名字
            arr[(int)file.file_path]=path+filename+"."+postfilename;//文件路徑
            return arr;
            //throw(new exception(htmlutility.htmlencode(idno.postedfile.filename)));
        }
      }
   }


if you have any question or comments,please mail to me ([email protected]) or discuss in our forum ( http://www.ai361.com/bbs).
正文完
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丰顺县| 惠来县| 满洲里市| 肥城市| 涞水县| 双城市| 华池县| 井研县| 灌云县| 渭源县| 阜宁县| 横峰县| 衢州市| 宝坻区| 共和县| 渭源县| 昂仁县| 梨树县| 洮南市| 武穴市| 华蓥市| 乌拉特中旗| 汕头市| 汶川县| 郎溪县| 安平县| 濉溪县| 达尔| 肥城市| 梧州市| 荣昌县| 永德县| 明星| 济宁市| 龙游县| 米脂县| 兰西县| 博湖县| 泊头市| 翁牛特旗| 延安市|