Exemple #1
0
        public static UploadFileClass upload(string mediaPath, HttpPostedFileBase file, byte type = 1)
        {
            UploadFileClass objUpload = new UploadFileClass();

            objUpload = Utility.GetUploadFile(mediaPath, file.FileName, true);
            file.SaveAs(objUpload.Fullpath);
            if (type == 1)
            {
                objUpload.pathThumb = Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName);
                Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName, 185, 111, false);
            }
            return(objUpload);
        }
        /// <summary>
        /// Uploads the specified media path.
        /// </summary>
        /// <param name="mediaPath">The media path.</param>
        /// <param name="file">The file.</param>
        /// <param name="width">The thumb width.</param>
        /// <param name="height">The thumb height.</param>
        /// <param name="type">The type. If type != 1 is not image file, so do not thumb</param>
        /// <returns>UploadFileClass.</returns>
        public static UploadFileClass upload(string mediaPath, HttpPostedFileBase file, int width, int height, byte type = 1)
        {
            UploadFileClass objUpload = new UploadFileClass();

            objUpload = Utility.GetUploadFile(HttpContext.Current.Server.MapPath(mediaPath), file.FileName, true);
            file.SaveAs(objUpload.Fullpath);
            if (type == 1)
            {
                // objUpload.pathThumb = Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName);
                objUpload.pathThumb = Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName, width, height, false);
            }
            return(objUpload);
        }
Exemple #3
0
        public static UploadFileClass GetUploadFile(string MediaPath, string strFileName, bool AddDatePath, string UID)
        {
            UploadFileClass tempUploadClass = new UploadFileClass();

            System.Text.RegularExpressions.Match matchResults;
            string strAdditionFolder = (AddDatePath ? String.Format(DateTime.Now.ToString("\\\\yyyy\\\\MM\\\\dd\\\\")) : UID);
            string strSaveFile       = strFileName;
            string strSaveFolder     = MediaPath + strAdditionFolder;

            //Check folder exist
            try
            {
                if (System.IO.Directory.Exists(strSaveFolder) == false)
                {
                    //Create Directory
                    System.IO.Directory.CreateDirectory(strSaveFolder);
                }
                if (System.IO.File.Exists(strSaveFolder + strSaveFile))
                {
                    while (System.IO.File.Exists(strSaveFolder + strSaveFile))
                    {
                        matchResults = System.Text.RegularExpressions.Regex.Match(strSaveFile, "(?<FileName>.*?)(?:\\((?<AutoNumber>\\d*?)\\))?\\.(?<FileType>\\w*?)(?!.)");
                        if (matchResults.Success)
                        {
                            if (matchResults.Groups["AutoNumber"].Value == string.Empty)
                            {
                                strSaveFile = matchResults.Groups["FileName"].Value + "(1)." + matchResults.Groups["FileType"].Value;
                            }
                            else
                            {
                                strSaveFile = matchResults.Groups["FileName"].Value + "(" + (int.Parse(matchResults.Groups["AutoNumber"].Value) + 1).ToString() + ")." + matchResults.Groups["FileType"].Value;
                            }
                        }
                    }
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            tempUploadClass.Virtualpath = strAdditionFolder.Replace("\\", "/") + strSaveFile;
            tempUploadClass.FileName    = strSaveFile;
            tempUploadClass.Fullpath    = strSaveFolder + strSaveFile;
            tempUploadClass.FolderPath  = strAdditionFolder.Replace("\\", "/");
            tempUploadClass.StrPathTemp = strSaveFolder;
            return(tempUploadClass);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mediaPath"></param>
        /// <param name="file"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static UploadFileClass upload(string mediaPath, HttpPostedFileBase file, int[] width, int[] height)
        {
            UploadFileClass objUpload = new UploadFileClass();

            objUpload = Utility.GetUploadFile(HttpContext.Current.Server.MapPath(mediaPath), file.FileName, true);
            file.SaveAs(objUpload.Fullpath);
            objUpload.pathThumb = Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName);
            for (int i = 0; i < width.Length; i++)
            {
                if (height[i] != null && height[i] > 0)
                {
                    Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName, width[i], height[i], false);
                }
                else
                {
                    Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName, width[i], width[i], false);
                }
            }
            //Utility.thumbImg(objUpload.StrPathTemp, objUpload.FolderPath, file.FileName, width, height, false);
            return(objUpload);
        }