private void ManagePostedData_AttachmentUploader_DailyRequestOnAbsence(FileUploaderAJAX AttachmentUploader)
 {
     try
     {
         string               separator    = "_";
         string               physicalPath = WebConfigurationManager.AppSettings["RequestAttachmentsPath"];
         string               path         = "ClientAttachments";
         HttpPostedFileAJAX   HPFA         = AttachmentUploader.PostedFile;
         string               RequestAttachmentSavedFileName = Guid.NewGuid().ToString() + separator + BUser.CurrentUser.Person.BarCode + separator + HPFA.FileName;
         ObjRequestAttachment RequestAttachment = new ObjRequestAttachment()
         {
             RequestAttachmentPath      = path,
             RequestAttachmentRealName  = HPFA.FileName,
             RequestAttachmentSavedPath = path + "/" + RequestAttachmentSavedFileName,
             RequestAttachmentSavedName = RequestAttachmentSavedFileName
         };
         this.StrRequestAttachment = this.JsSerializer.Serialize(RequestAttachment);
         AttachmentUploader.PostedFile.responseMessage_Uploaded_Saved    = " ";
         AttachmentUploader.PostedFile.responseMessage_Uploaded_NotSaved = " ";
         AttachmentUploader.SaveAs(path, RequestAttachmentSavedFileName);
         File.Move(Server.MapPath(path + "\\" + RequestAttachmentSavedFileName), physicalPath + "\\" + RequestAttachmentSavedFileName);
     }
     catch (Exception ex)
     {
         ObjRequestAttachment RequestAttachment = new ObjRequestAttachment()
         {
             IsErrorOccured = true,
             Message        = GetLocalResourceObject("UploadingError").ToString()
         };
         this.StrRequestAttachment = this.JsSerializer.Serialize(RequestAttachment);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Quản lý File Upload (mọi loại file)
        /// </summary>
        /// <param name="fileUpload">FileUploaderAJAX object</param>
        /// <param name="f">true: Đổi tên file theo thời gian upload, false: lấy tên file gốc</param>
        /// <returns></returns>
        public static string ProcessFileUpload(FileUploaderAJAX fileUpload, bool f)
        {
            string FileName = "";

            try
            {
                HttpPostedFileAJAX pf = fileUpload.PostedFile;
                int    index          = pf.ContentType.IndexOf("/");
                string strExtension   = pf.ContentType.Substring(index + 1);
                if (strExtension == "pjpeg" || strExtension == "jpeg" || strExtension == "jpg")
                {
                    strExtension = "jpg";
                }
                if (f == false)
                {
                    FileName = pf.FileName;
                }
                else if (f == true)
                {
                    FileName = Globals.GetFileName() + "." + strExtension;
                }
                fileUpload.SaveAs(Globals.GetUploadsUrl() + FileName);
            }
            catch { }
            return(FileName);
        }
        /// <summary>
        /// Upload file from FileUpload Control and return virtual path
        /// </summary>
        /// <param name="fileUploadControl">FileUpload Control to be upload</param>
        /// <param name="path">Path from User File folder</param>
        /// <param name="random">Generate Random file name</param>
        /// <param name="createByDate"></param>
        /// <returns>Virtual path to newly uploaded file</returns>
        public static string Upload(FileUploaderAJAX fileUploadControl, string path, bool random, bool createByDate)
        {
            // Image\\News\\
            try
            {
                string savePath = AppDomain.CurrentDomain.BaseDirectory;
                string virtualPath;
                if (path[0] != '~')
                {
                    virtualPath = "UserFiles\\" + path;
                }
                else
                {
                    path        = path.Remove(0, 2);
                    virtualPath = path;
                }

                virtualPath = Text.EnsureSlash(virtualPath);

                if (!Directory.Exists(savePath + virtualPath))
                {
                    Directory.CreateDirectory(savePath + virtualPath);
                }

                if (createByDate)
                {
                    virtualPath += string.Format("{2}_{1}_{0}\\", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
                }
                if (!Directory.Exists(savePath + virtualPath))
                {
                    Directory.CreateDirectory(savePath + virtualPath);
                }

                if (fileUploadControl.IsPosting)
                {
                    string             fileName;
                    HttpPostedFileAJAX pf = fileUploadControl.PostedFile;
                    if (random)
                    {
                        fileName = Text.RandomString(24, true) + pf.FileName.Substring(pf.FileName.IndexOf('.'));
                    }
                    else
                    {
                        fileName = pf.FileName;
                    }
                    //    savePath += string.Format("{0}{1}\\", DateTime.Now.Month, DateTime.Now.Year);
                    virtualPath += fileName;
                    fileUploadControl.SaveAs(savePath + virtualPath);
                    virtualPath = virtualPath.Replace("\\", "/");
                    return("/" + virtualPath);
                }
                return(String.Empty);
            }
            catch (Exception ex)
            {
                logger.Error("Can not upload files", ex);
                return(String.Empty);
            }
        }
Esempio n. 4
0
 private void ManagePostedData_AttachmentUploader_RequestHistory(FileUploaderAJAX AttachmentUploader)
 {
     try
     {
         string             separator = "_";
         string             RequestAttachmentsPathKey = AppFolders.RequestsAttachments.ToString();
         string             path = AppDomain.CurrentDomain.BaseDirectory + RequestAttachmentsPathKey;
         HttpPostedFileAJAX HPFA = AttachmentUploader.PostedFile;
         string             operatorSeparator = string.Empty;
         if (this.RequestRegisterBusiness.IsCurrentUserOperator)
         {
             operatorSeparator = "Operator";
         }
         string RequestAttachmentSavedFileName  = Guid.NewGuid().ToString() + separator + operatorSeparator + separator + BUser.CurrentUser.Person.BarCode + separator + this.StringBuilder.CreateString(HPFA.FileName, StringGeneratorExceptionType.ClientAttachments);
         ObjRequestAttachment RequestAttachment = new ObjRequestAttachment()
         {
             RequestAttachmentPath      = path,
             RequestAttachmentRealName  = HPFA.FileName,
             RequestAttachmentSavedPath = path + "/" + RequestAttachmentSavedFileName,
             RequestAttachmentSavedName = RequestAttachmentSavedFileName
         };
         this.StrRequestAttachment = this.JsSerializer.Serialize(RequestAttachment);
         AttachmentUploader.PostedFile.responseMessage_Uploaded_Saved    = " ";
         AttachmentUploader.PostedFile.responseMessage_Uploaded_NotSaved = " ";
         AttachmentUploader.SaveAs(AppFolders.RequestsAttachments.ToString(), RequestAttachmentSavedFileName);
     }
     catch (Exception ex)
     {
         ObjRequestAttachment RequestAttachment = new ObjRequestAttachment()
         {
             IsErrorOccured = true,
             Message        = GetLocalResourceObject("UploadingError").ToString()
         };
         this.StrRequestAttachment = this.JsSerializer.Serialize(RequestAttachment);
     }
 }