国产探花免费观看_亚洲丰满少妇自慰呻吟_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).
正文完
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双鸭山市| 冕宁县| 靖宇县| 女性| 中江县| 潮安县| 济阳县| 高淳县| 陆河县| 泰州市| 嘉善县| 儋州市| 罗江县| 晴隆县| 呼伦贝尔市| 灵台县| 星座| 曲松县| 梧州市| 景洪市| 平度市| 运城市| 广州市| 衢州市| 贡嘎县| 凤山市| 伽师县| 鄂托克旗| 陆河县| 东明县| 平定县| 苏尼特右旗| 云安县| 如东县| 和龙市| 浮山县| 桂东县| 香格里拉县| 双流县| 山丹县| 大荔县|