示例#1
0
 public static void uploadFileControl(HttpPostedFile hpf, string savePath, string FileType, out string OutPath)
 {
     OutPath = string.Empty;
     if (hpf != null)
     {
         if (!string.IsNullOrEmpty(hpf.ToString()))
         {
             try
             {
                 string ext = System.IO.Path.GetExtension(hpf.FileName).ToLower();
                 if (!IsFileType(FileType, ext))
                 {
                     return;
                 }
                 string filename = Guid.NewGuid().ToString("N", System.Globalization.CultureInfo.InvariantCulture) + ext;//文件重命名_userId_CourseID
                 string pathStr = HttpContext.Current.Server.MapPath("/" + savePath);
                 if (!System.IO.Directory.Exists(pathStr))
                 {
                     System.IO.Directory.CreateDirectory(pathStr);
                 }
                 string path = "/" + savePath + "/" + filename;
                 hpf.SaveAs(HttpContext.Current.Server.MapPath(path));
                 OutPath = path;
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
     else
     {
         OutPath = string.Empty;
     }
 }
 public bool Validation(HttpPostedFile value)
 {
     if (value == null)
         {
             return false;
         }
         string strExtension = value.ToString();
         string extension = Path.GetExtension(strExtension);
         if (extension == null)
         {
             return false;
         }
         if (extension != ".srt")
         {
             return false;
         }
         return true;
 }