Exemplo n.º 1
0
        private static string UploadFileMaster(HttpPostedFileBase UploadedFile, ContentPathMode mode, string UploadDirPath, string FileRenameToNewName = "")
        {
            string UploadedFileName = "";

            if (UploadedFile.ContentLength > 0)
            {
                var fileName = Path.GetFileName(UploadedFile.FileName);
                UploadedFileName = (FileRenameToNewName == "" ? fileName : FileRenameToNewName);
                string path = string.Empty;;
                if (mode.ToString() == "relative")
                {
                    path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(UploadDirPath), UploadedFileName);
                }
                else
                {
                    path = Path.Combine(UploadDirPath, UploadedFileName);
                }
                UploadedFile.SaveAs(path);
            }
            return(UploadedFileName);
        }
Exemplo n.º 2
0
        public static string UploadFileAndRename(HttpPostedFileBase UploadedFile, ContentPathMode mode, string UploadDirPath = "~/Upload/Package",
                                                 bool RenameInGuidFormat = true)
        {
            string   UploadedFileName = "";
            DateTime dt             = DateTime.Now;
            string   fileNamePrefix = "";

            if (UploadedFile.ContentLength > 0)
            {
                if (RenameInGuidFormat)
                {
                    fileNamePrefix = AppGuid.NewGuid(Convert.ToChar("D")) + "__";
                }
                else
                {
                    fileNamePrefix = string.Format("{0:dd-MM-yyyy-HH.mm.ss}", dt) + "__";
                }
                var fileName = fileNamePrefix + Path.GetFileName(UploadedFile.FileName);
                UploadedFileName = UploadFileMaster(UploadedFile, mode, UploadDirPath, fileName);
            }
            return(UploadedFileName);
        }
Exemplo n.º 3
0
        /* public static bool UploadFile(HttpPostedFileBase UploadedFile, string UploadDirPath = "~/Content/Uploaded/")
         * {
         *   string UploadedFileName = UploadFileMaster(UploadedFile, UploadDirPath, UploadedFile.FileName);
         *   if (UploadedFileName != "")
         *   {
         *       return UploadedFileName;
         *   }
         *   return true;
         *
         * }
         */

        public static string UploadDocumentAndRename(HttpPostedFileBase UploadedFile, ContentPathMode mode, string UploadDirPath = "~/Upload/Package")
        {
            string   UploadedFileName = "";
            DateTime dt             = DateTime.Now;
            string   fileNamePrefix = "";

            if (UploadedFile.ContentLength > 0)
            {
                fileNamePrefix = Guid.NewGuid().ToString("D");
                var fileName = fileNamePrefix + Path.GetExtension(UploadedFile.FileName);
                UploadedFileName = UploadFileMaster(UploadedFile, mode, UploadDirPath, fileName);
            }
            return(UploadedFileName);
        }