国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
文件上傳

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

/// <summary>
/// Summary description for UploadFile
/// </summary>
public class UploadFile
{
    private string[] AllowFileType; //
所允許的文件類型
    private double FileLength; //
所允許的文件大小(KB)
    private string SavePath; //
文件的存儲(chǔ)路徑
    private string SaveFile; //
上傳后的文件名
    private string Error; //
存儲(chǔ)錯(cuò)誤信息
    private string FileExtesion; //
上傳文件的擴(kuò)展名

    /// <summary>
    ///
構(gòu)造函數(shù)
    /// </summary>
    /// <param name="allFileType">
允許的文件類型,多個(gè)以","分開(kāi)</param>
    /// <param name="fileLength">
文件大小</param>
    /// <param name="savePath">
保存路徑</param>
    public UploadFile(string allFileType, double fileLength, string savePath)
    {
        char[] sp = { ',' };
        AllowFileType = allFileType.Split(sp);
        FileLength = fileLength * 1024;
        SavePath = savePath;
    }

    /// <summary>
    ///
返回生成的文件名
    /// </summary>
    public string FileName
    {
        get
        {
            return SaveFile;
        }
    }

    /// <summary>
    ///
返回出錯(cuò)信息
    /// </summary>
    public string ErrorMessage
    {
        get
        {
            return Error;
        }
    }

    /// <summary>
    ///
根據(jù)SavePath,生成文件名
    /// </summary>
    /// <returns></returns>
    private string MakeFileName(string fileType,string fileName)
    {
        string file = this.SavePath + "\\" + DateTime.Now.ToString("yyMMddhhmmss") + fileName;
        while (File.Exists(file))
        {
            file = this.SavePath + "\\" + DateTime.Now.ToString("yyMMddhhmmss") + fileName;
        }
        return file;
    }

    /// <summary>
    ///
檢查文件類型
    /// </summary>
    /// <param name="fileEx">MIME
內(nèi)容</param>
    /// <returns></returns>
    private bool CheckFileExt(string fileEx)
    {
        bool result = false;
        for (int i = 0; i < this.AllowFileType.Length; i++)
        {
            if (fileEx.IndexOf(this.AllowFileType[i].ToLower()) > -1)
            {
                result = true;
                break;
            }
        }
        return result;
    }

    public bool UpLoad(System.Web.UI.WebControls.FileUpload file)
    {
        bool result = true;
        try
        {
            //
查看文件長(zhǎng)度
            if (file.PostedFile.ContentLength > (this.FileLength))
            {
                this.Error = "
文件大小超出范允許的范圍!";
                return false;
            }

            string fileName = Path.GetFileName(file.PostedFile.FileName);
            this.FileExtesion = Path.GetExtension(fileName);

            if (!CheckFileExt(this.FileExtesion.ToLower()))
            {
                this.Error = "
文件類型" + this.FileExtesion + "不允許!";
                return false;
            }
            //
取得要保存的文件名
            string UpFile = this.MakeFileName(this.FileExtesion, fileName);
            //
保存文件
            file.PostedFile.SaveAs(UpFile);

            //返回文件名
            this.SaveFile = Path.GetFileName(UpFile);

        }
        catch (Exception e)
        {
            result = false;
            this.Error = e.Message;
        }
        return result;
    }
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C#獲取文件名稱、路徑、后綴名
文件操作 File
C#實(shí)現(xiàn)多線程下載文件的方法
C# 大文件分段上傳,下載
文件轉(zhuǎn)化成二進(jìn)制以及base64編碼字符串返回
java 從網(wǎng)絡(luò)Url中下載文件
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服