<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      ASP.NET中上傳下載文件

      [摘要]//檢查上傳文件不為空 if(File1.PostedFile!=null) string nam = File1.PostedFile.FileName ; //取得文件名(抱括路徑)里最后一個"."的索引 int i= nam.Last...

      //檢查上傳文件不為空
         if(File1.PostedFile!=null)
         {    
          string nam = File1.PostedFile.FileName ;
          //取得文件名(抱括路徑)里最后一個"."的索引
          int i= nam.LastIndexOf(".");
          //取得文件擴展名
          string newext =nam.Substring(i);
          //這里我自動根據日期和文件大小不同為文件命名,確保文件名不重復
          DateTime now = DateTime.Now;
          string newname=now.DayOfYear.ToString()+File1.PostedFile.ContentLength.ToString();
          //保存文件到你所要的目錄,這里是IIS根目錄下的upload目錄.你可以改變.
          //注意: 我這里用Server.MapPath()取當前文件的絕對目錄.在asp.net里""必須用""代替
          File1.PostedFile.SaveAs(Server.MapPath("upload"+newname+newext));

          this.HyperLink1.NavigateUrl  ="upload"+newname+newext;

          //得到這個文件的相關屬性:文件名,文件類型,文件大小
          //fname.Text=File1.PostedFile.FileName;
          //fenc.Text=File1.PostedFile.ContentType ;
          //fsize.Text=File1.PostedFile.ContentLength.ToString();
         }





      日韩精品一区二区三区高清