Пример #1
0
        public string SaveThumb(string base64Avatar, string fileName)
        {
            string          PathServer   = ControllerContext.HttpContext.Server.MapPath("~");
            string          PathSeverNew = ConfigurationManager.AppSettings["AvatarUrl"];
            UploadFileClass objUpload    = new UploadFileClass();

            objUpload = Utils.GetUploadFile(Server.MapPath(PathSeverNew), fileName, true);
            Utils.UploadImageWithBase64(base64Avatar, PathServer, PathSeverNew + objUpload.Virtualpath);
            return(PathSeverNew + objUpload.Virtualpath);
        }
Пример #2
0
        public string SaveThumb(string base64Avatar, string fileName)
        {
            string          PathServer   = ControllerContext.HttpContext.Server.MapPath("~");
            string          PathSeverNew = ConfigurationManager.AppSettings["ImageUrl"];
            UploadFileClass objUpload    = new UploadFileClass();

            objUpload = GetUploadFile(Server.MapPath(PathSeverNew), fileName ?? DateTime.Now.ToString("yyyymmddmmss"), true);
            UploadImageWithBase64(base64Avatar, PathServer, PathSeverNew + "\\" + objUpload.Virtualpath);
            return(PathSeverNew + "\\" + objUpload.Virtualpath);
        }
Пример #3
0
        public static UploadFileClass GetUploadFile(string MediaPath, string strFileName, bool AddDatePath)
        {
            UploadFileClass tempUploadClass = new UploadFileClass();

            System.Text.RegularExpressions.Match matchResults;
            string strAdditionFolder = (AddDatePath ? String.Format(DateTime.Now.ToString("yyyy\\\\MM\\\\")) : "");
            string strSaveFile       = strFileName;
            // mac dinh them ngay thang nam trong ten file
            //matchResults = System.Text.RegularExpressions.Regex.Match(strSaveFile, "(?<FileName>.*?)(?:\\((?<AutoNumber>\\d*?)\\))?\\.(?<FileType>\\w*?)(?!.)");
            //strSaveFile = matchResults.Groups["FileName"].Value + "("+ DateTime.Now.ToString("ddMMyyyyHHmmss") + ")." + matchResults.Groups["FileType"].Value;
            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);
        }