麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

csharp: Gets a files formatted size.

2019-11-17 02:26:11
字體:
來源:轉載
供稿:網友

csharp: Gets a files formatted size.

  /*            asp.net 默認上傳文件是4M ,可以修改服務配置..            <system.web>           <!-- 指示 ASP.NET 支持的最大文件上載大小。           該限制可用于防止因用戶將大量文件傳遞到該服務器而導致的拒絕服務攻擊。           指定的大小以 KB 為單位。默認值為 4096 KB (4 MB)。最大為:2097151 KB           此處改為40M大小的文件上傳限制。           -->           <httPRuntime maxRequestLength = "2097151" useFullyQualifiedRedirectUrl="true"/>           </system.web>            */        /// <summary>        /// Gets a files formatted size.        /// </summary>        /// <param name="file">The file to return size of.</param>        /// <returns></returns>        //public static string GetFileSize(this FileInfo file)        //{        //    try        //    {        //        //determine all file sizes        //        double sizeinbytes = file.Length;        //        double sizeinkbytes = Math.Round((sizeinbytes / 1024));        //        double sizeinmbytes = Math.Round((sizeinkbytes / 1024));        //        double sizeingbytes = Math.Round((sizeinmbytes / 1024));        //        if (sizeingbytes > 1)        //            return string.Format("{0} GB", sizeingbytes); //returns size in gigabytes        //        else if (sizeinmbytes > 1)        //            return string.Format("{0} MB", sizeinmbytes); //returns size in megabytes if less than one gigabyte        //        else if (sizeinkbytes > 1)        //            return string.Format("{0} KB", sizeinkbytes); //returns size in kilabytes if less than one megabyte        //        else        //            return string.Format("{0} B", sizeinbytes); //returns size in bytes if less than one kilabyte        //    }        //    catch { return "Error Getting Size"; } //catches any possible error and just returns error getting size        //}        /// <summary>        /// Gets a files formatted size.        /// 獲得文件大小        /// 涂聚文        ///         /// Geovin Du        /// </summary>        /// <param name="file"></param>        /// <returns></returns>        public string GetFileSize(double file)        {            try            {                //1.                double byteSize = Math.Round(file / 1024 * 100) * 0.01;                string suffix = "KB";                if (byteSize > 1000)                {                    byteSize = Math.Round(byteSize * .001 * 100) * .01;                    suffix = "MB";                }                double byteGSize = Math.Round(byteSize / 1024 * 100) * 0.01;                if (byteGSize > 1000)                {                    byteGSize = Math.Round(byteGSize * .001 * 100) * .01;                    suffix = "GB";                }                return byteSize.ToString() + suffix;                //2.                //determine all file sizes                //double sizeinbytes = file;                //double sizeinkbytes = Math.Round((sizeinbytes / 1024));                //double sizeinmbytes = Math.Round((sizeinkbytes / 1024));                //double sizeingbytes = Math.Round((sizeinmbytes / 1024));                //if (sizeingbytes > 1)                //    return string.Format("{0:0.00} GB", sizeingbytes); //returns size in gigabytes                //else if (sizeinmbytes > 1)                //    return string.Format("{0:0.00} MB", sizeinmbytes); //returns size in megabytes if less than one gigabyte                //else if (sizeinkbytes > 1)                //    return string.Format("{0:0.00} KB", sizeinkbytes); //returns size in kilabytes if less than one megabyte                //else                //    return string.Format("{0} B", sizeinbytes); //returns size in bytes if less than one kilabyte            }            catch             {                 return "Error Getting Size";             } //catches any possible error and just returns error getting size        }

  

  /// <summary>        ///         /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        protected void Button1_Click(object sender, EventArgs e)        {            int FileNum = 0;            // Clear the BulletedList.            BulletedList1.Items.Clear();            string filepath = Server.MapPath("./") + "UploadFile";            string filename = DateTime.Now.ToString("yyyyMMddHHmmss");            HttpFileCollection hfc = Request.Files;            //1            for (int i = 0; i < hfc.Count; i++)            {                HttpPostedFile hpf = hfc[i];                if (hfc[i].ContentLength > 0)                {                    hpf.SaveAs(filepath + "/" + filename + System.IO.Path.GetFileName(hpf.FileName));                    FileNum++;                    //uploadFiles.SaveAs(filepath + "/" + filename + System.IO.Path.GetFileName(hpf.FileName));                    FileUpload1.SaveAs(filepath + "/" + filename + System.IO.Path.GetFileName(hpf.FileName));                    FileUpload2.SaveAs(filepath + "/" + filename + System.IO.Path.GetFileName(hpf.FileName));                }                else                {                    Response.Write("<scr

  

        /// <summary>        ///         /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        protected void Page_Load(object sender, EventArgs e)        {            this.AddFile.Click += new System.EventHandler(this.AddFile_Click);            this.RemvFile.Click += new System.EventHandler(this.RemvFile_Click);            this.Upload.ServerClick += new System.EventHandler(this.Upload_ServerClick);        }        /// <summary>        /// AddFile will add the path of the client side file that is currently in the PostedFile        /// property of the HttpInputFile control to the listbox.        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void AddFile_Click(object sender, System.EventArgs e)        {            if (Page.IsPostBack == true)            {                hif.Add(FindFile);                double size = FindFile.PostedFile.ContentLength;                string filesize = GetFileSize(size);                ListBox1.Items.Add(FindFile.PostedFile.FileName + "  文件大小:" + filesize);               // FindFile.PostedFile.Conten
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 4399一级成人毛片 | 狠狠操精品视频 | 成人午夜视频免费在线观看 | 国产成人高潮免费观看精品 | 国产成人强伦免费视频网站 | 91成人免费视频 | 欧美日韩免费在线观看视频 | 久草干| xxxx18韩国护士hd老师 | 毛片成人 | 国产妞干网 | 亚洲经典视频 | 久草在线视频免费播放 | 国产老师做www爽爽爽视频 | 天天操很很操 | 久久久久久久久淑女av国产精品 | 色诱亚洲精品久久久久久 | 超碰97最新 | 色99久久 | 99这里精品| 激情亚洲一区二区三区 | 一级爱爱| 欧美成人一区二区三区 | 成人做爰高潮片免费视频美国 | 91www成人久久| 欧洲精品色 | 亚洲一区二区在线 | 免费观看国产精品视频 | 91情侣偷在线精品国产 | 国产日韩在线观看视频 | 男人的天堂视频网站 | 久草视频2 | 蜜桃视频在线免费观看 | 久久我不卡 | 日本aaaa片毛片免费观蜜桃 | 日韩精品久久久久久久九岛 | 黄网站免费观看视频 | 国产精品久久久久久久久粉嫩 | 91短视频在线视频 | 国产亚洲精品yxsp | 国产91对白叫床清晰播放 |