第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Asp.net上傳文件至目錄

標(biāo)簽:
產(chǎn)品

Asp.net上传文件,把文件存入至目录中。限制上传文件大小,限制上传文件格式。存取得原来文件名,创建新的文件名。

把文件临时存入临时目录中,处理完毕,最后再移至真正目录。

参考代码:

复制代码 //上传时,判断文件是否大于限定大小
        if (this.FileUpload1.PostedFile.ContentLength > 104857600) //单位KB
        {
            objInsusJsUtility.JsAlert("You select the file larger than 100MB");
            return;
        }

        //创建一个临时文件夹
        string tempPath = "~/Temp/";
        //判断目录是否存在
        if (!Directory.Exists(Server.MapPath(tempPath)))
        {
            //如果不存在,创建它
            Directory.CreateDirectory(Server.MapPath(tempPath));
        }

       //取得上传文件
        string uploadfile = FileUpload1.PostedFile.FileName;
        //取得原文件名,存入数据库中,这样在aspx显示回原来的文件名
        string oldFileName = uploadfile.Substring(uploadfile.LastIndexOf(@"\") + 1);
        //取得文件的扩展名
        string fileExtension = uploadfile.Substring(uploadfile.LastIndexOf("."));
        //产生新文件名
        string newFileName = objGuid.ToString() + fileExtension;

        //建立存储的目录
        string directory = Mediadirectory + this.ddlMediaType.SelectedItem.Value + "/";
        
        //判断目录是否存在
        if (!Directory.Exists(Server.MapPath(directory)))
        {
           //如果不存在,创建它
            Directory.CreateDirectory(Server.MapPath(directory));
        }

        //新文件
        string newFile = Server.MapPath(tempPath + newFileName);
        
        //保存文件(暂存入一个临时文件夹中)
        FileUpload1.SaveAs(newFile);

        //限定上传的文件类型
        string[] fileClass = { "7076", "4838" };  //7076 is FLV;4838 is wmv;
        if (!InsusBase.CompareFileClass(newFile, fileClass))
        {
            objInsusJsUtility.JsAlert("You did not specify a media file.The file format is wmv,flv");
            return;
        }

        try
        {
           //存入数据库中
            objMedia.Insert(this.ddlMediaType.SelectedItem.Value, this.txtSubject.Text.Trim(), this.txtDescription.Text.Trim(), directory, oldFileName, newFileName);
            //把文件从临时文件夹中,移至真正的目录。
            File.Move(newFile, Server.MapPath(directory + newFileName));
            objInsusJsUtility.JsAlert("视频上传成功。", "this", "Media.aspx");
        }
        catch (Exception ex)
        {
            //抛出异常
            InsusBase.InsusException(ex);
        }复制代码

 

Web.config配置可上传大文件,asp.net默认情况之下只能上传4MB,另外一点就是,maxRequestLength单位是MB。

 <system.web>      
        <httpRuntime maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>
    </system.web>

 

 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消