Exemplo n.º 1
0
 public string AddImage(string imageName, string userID, System.Web.HttpPostedFile image)
 {
     string imageID = System.Guid.NewGuid().ToString();
     string imageType;
     switch (image.ContentType)
     {
         case "image/png":
             imageType = "png";
             break;
         case "image/jpeg":
         case "image/pjpeg":
             imageType = "jpg";
             break;
         case "image/webp":
             imageType = "webp";
             break;
         default:
             throw new InvalidOperationException("Unknown image content type: " + image.ContentType);
     }
     image.SaveAs(ImagesDir + imageID + "." + imageType);
     AddRecord(new string[]
     {
         imageID,
         EscapeForCsv(imageName),
         imageType,
         userID
     });
     return imageID;
 }
        public static string SaveFile(System.Web.UI.WebControls.FileUpload fu, string url)
        {
            try
            {
                string filename = "";
                if (fu.HasFile)
                {
                    FileInfo finfo = new FileInfo(url + fu.FileName);
                    finfo = new FileInfo(url + fu.FileName);
                    int dem = 0;
                    filename = fu.FileName;
                    while (finfo.Exists)
                    {
                        dem++;
                        filename = dem.ToString() + fu.FileName;
                        finfo = new FileInfo(url + filename);
                    }
                    fu.SaveAs(url + filename);

                }
                return filename;
            }
            catch (Exception)
            {

                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Instantiates a DataAdapter object which implements the specified Excel document
        /// </summary>
        /// <param name="connectionString">The name of the excel file that wil be connected to.</param>
        public ExcelDataAdapter(System.Web.HttpPostedFile postedfile)
        {
            if (!postedfile.FileName.EndsWith(".xls"))
                throw new ArgumentException("Only Microsoft Excel spreadsheets (.xls) are supported by the Excel Data Adapter.");

            _temporaryFile = Path.GetTempFileName();
            postedfile.SaveAs(_temporaryFile);

            SetupConnection(_temporaryFile);
        }
Exemplo n.º 4
0
    public static void UploadImage(System.Web.UI.WebControls.FileUpload fileupload, string path)
    {
        try
        {
            fileupload.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
        }
        catch (Exception)
        {

        }
    }
Exemplo n.º 5
0
 public static string FileUpload(System.Web.HttpPostedFileBase file, string path)
 {
     if (file != null && file.ContentLength > 0)
     {
         file.SaveAs(HttpContext.Current.Server.MapPath(path + Utility.SetPagePlug(file.FileName.Split('.')[0].ToString()) + Path.GetExtension(file.FileName)));
         return path + Utility.SetPagePlug(file.FileName.Split('.')[0].ToString()) + Path.GetExtension(file.FileName);
     }
     else
     {
         return "";
     }
 }
Exemplo n.º 6
0
    public static string UploadImage(System.Web.UI.WebControls.FileUpload fileupload, string fill)
    {
        try
        {
            string path = "~/images/products/" + DateTime.Now.ToString("yyyyMMddhhmmss") + fill + "." + fileupload.FileName;
            fileupload.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
            return path;
        }
        catch (Exception)
        {

            return "";
        }
    }
Exemplo n.º 7
0
        // Shared private method in order to save a file cheecking if the content is present.
        // If there is content, the filename is saved.
        private string save(System.Web.HttpPostedFileBase file, string tag, string folderpath)
        {
            if (file != null && file.ContentLength > 0)
            {

                var fileName = string.Format("{0}_{1}", tag, Path.GetFileName(file.FileName));

                var path = Path.Combine(folderpath, fileName);

                file.SaveAs(path);

                return fileName;
            }
            return null;
        }
Exemplo n.º 8
0
        public void SaveFile(System.Web.HttpPostedFileBase httpPostedFileBase)
        {
            int lastPeriod = httpPostedFileBase.FileName.LastIndexOf(".");
            string fileName = httpPostedFileBase.FileName;
            httpPostedFileBase.SaveAs(HttpContext.Current.Server.MapPath("~/Upload/") + fileName);

            BlogMedia media = new BlogMedia();
            media.BlogConfigId = this.blogConfig.BlogConfigId;
            media.FileName = fileName;
            media.FilePath = HttpContext.Current.Server.MapPath("/Upload/") + fileName;
            //info.url = "http://" + host + "/files/media/image/" + media.name;
            media.ServerPath = "http://" + this.blogConfig.Host + "/upload/" + fileName;
            media.CreateDate = DateTime.Now;
            media.CreatedById = SessionHandler.CurrentUserId;
            repo.Add(media);
            repo.Save();
        }
        public string UploadMetadataInFileSystem(
            System.Web.UI.WebControls.FileUpload fileUploader,
            System.Web.HttpServerUtility Server,
            string tableSchema,
            string tableName,
            string columnName,
            string id)
        {
            string _retval = null;
            if (fileUploader.HasFile)
            {
                // Make sure that a PDF has been uploaded
                if (true == Framework.Web.WebFormApplicationUploadFilePathBuilder.ValidateFileName(
                    tableSchema, tableName, columnName, id,
                    fileUploader.FileName))
                {
                    string fileDirectory = Framework.Web.WebFormApplicationUploadFilePathBuilder.BuildFileDirectory(
                        tableSchema, tableName, columnName, id,
                        fileUploader.FileName);
                    string filePath = fileDirectory + "/" + fileUploader.FileName;
                    string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileUploader.FileName);
                    string fileExtension = System.IO.Path.GetExtension(fileUploader.FileName);
                    int iteration = 1;

                    while (System.IO.File.Exists(Server.MapPath(filePath)))
                    {
                        filePath = string.Concat(fileDirectory, fileNameWithoutExtension, "-", iteration, fileExtension);
                        iteration++;
                    }

                    // Save the file to disk and set the value of the brochurePath parameter
                    fileUploader.SaveAs(Server.MapPath(filePath));
                    _retval = filePath;
                }
            }

            return _retval;
        }
Exemplo n.º 10
0
        public virtual ImagePreviewDTO SaveAspect(System.Web.HttpPostedFile file)
        {
            string thumbFolder = string.Format("{0}\\Thumb", this._folderServerPath);
            if (!System.IO.Directory.Exists(this._orignalImageServerPath))
            {
                System.IO.Directory.CreateDirectory(this._orignalImageServerPath);
            }
            if (!System.IO.Directory.Exists(thumbFolder))
            {
                System.IO.Directory.CreateDirectory(thumbFolder);
            }
            string fileName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + file.FileName;
            string orignalPath = string.Format(this._orignalImageServerPath + "\\{0}", fileName);
            string thumbPath = string.Format(thumbFolder + "\\{0}", fileName);

            ImagePreviewDTO previewDTO = new ImagePreviewDTO();
            previewDTO.FileName = fileName;
            previewDTO.Key = Guid.NewGuid().ToString();
            previewDTO.OrignalPath = string.Format("{0}/Orignal/{1}", this._folderPath, fileName);

            try
            {
                //保存原图
                file.SaveAs(orignalPath);
                //缩略图100*65

                if (fileName.IndexOf(".doc") > 0 || fileName.IndexOf(".docx") > 0)
                {
                    string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons");
                    orignalPath = string.Format(iconServerPath + "\\{0}", "word.png");
                    thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                    IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW");
                    previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                }
                else if (fileName.IndexOf(".xls") > 0 || fileName.IndexOf("xlsx") > 0)
                {
                    string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons");
                    orignalPath = string.Format(iconServerPath + "\\{0}", "excel.png");
                    thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                    IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW");
                    previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                }
                else if (fileName.IndexOf("ppt") > 0 || fileName.IndexOf(".pptx") > 0)
                {
                    string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons");
                    orignalPath = string.Format(iconServerPath + "\\{0}", "ppt.png");
                    thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                    IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW");
                    previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png");
                }
                else
                {
                    IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW");
                    previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName);
                }
            }
            catch (System.IO.IOException ex)
            {
                if (System.IO.File.Exists(orignalPath))
                {
                    System.IO.File.Delete(orignalPath);
                }
                if (System.IO.File.Exists(thumbPath))
                {
                    System.IO.File.Delete(thumbPath);
                }
            }

            return previewDTO;
        }
Exemplo n.º 11
0
        public string SaveImage(System.Web.HttpPostedFileBase photo)
        {
            var folder = HttpContext.Current.Server.MapPath(FileFolder);
            if (System.IO.Directory.Exists(folder) == false)
            {
                System.IO.Directory.CreateDirectory(folder);
            }

            //TODO: kiểm tra file hợp lệ

            //Save file
            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(folder + "/" + photo.FileName);
            photo.SaveAs(System.IO.Path.Combine(folder, fileName));
            return fileName;
        }
        internal bool ProcessFileUpload(FileManagerItemInfo destDir, System.Web.HttpPostedFile uploadedFile, out string script)
        {
            UploadFileCancelEventArgs cancelArg = new UploadFileCancelEventArgs();
            cancelArg.DestinationDirectory = destDir;
            cancelArg.PostedFile = uploadedFile;
            OnFileUploading(cancelArg);

            if (cancelArg.Cancel)
            {
                script = ClientMessageEventReference(cancelArg.ClientMessage);
                return false;
            }

            string saveName = cancelArg.SaveName;
            string fileNameWithoutExtension = saveName.Substring(0, saveName.LastIndexOf('.'));
            string extension = saveName.Substring(saveName.LastIndexOf('.'));

            string ext = extension.ToLower(CultureInfo.InvariantCulture).TrimStart('.');
            if (HiddenFilesArray.Contains(ext) ||
                    ProhibitedFilesArray.Contains(ext))
            {
                script = ClientMessageEventReference(null);
                return false;
            }

            string newFileName = GetNotDuplicatedFileName(destDir, fileNameWithoutExtension, extension);
            FileManagerItemInfo itemInfo = ResolveFileManagerItemInfo(VirtualPathUtility.AppendTrailingSlash(destDir.FileManagerPath) + newFileName);

            uploadedFile.SaveAs(itemInfo.PhysicalPath);

            UploadFileEventArgs arg = new UploadFileEventArgs();
            arg.UploadedFile = itemInfo;
            OnFileUploaded(arg);

            script = ClientRefreshEventReference;
            return true;
        }
Exemplo n.º 13
0
    public bool uploadFile(ref System.Web.UI.WebControls.FileUpload fu, string role)
    {
        bool result = false;

        try
        {
            if (fu.HasFile && fu.FileContent.Length != 0)
            {
               string url = _context.Server.MapPath("~/" + role + "/Reports");
               string uploadedFile = url + @"\" + fu.FileName;
               fu.SaveAs(uploadedFile);

            }

        }
        catch (Exception)
        {
            result = false;
            throw;
        }

        return result;
    }
Exemplo n.º 14
0
        //writtenBy Azizi 95_03_12
        private string SaveImage(System.Web.HttpPostedFileBase Picture)
        {
            string filename = "";
            GetFileExtension Ext = new GetFileExtension();
            if (Ext.GetExtension(Picture.FileName) == "jpg" || Ext.GetExtension(Picture.FileName) == "png" || Ext.GetExtension(Picture.FileName) == "jpeg" || Ext.GetExtension(Picture.FileName) == "png")
            {
                filename = DateTime.Now.ToString("ddMMyyhhmmss") + Session["admin"].ToString() + "." + Ext.GetExtension(Picture.FileName);
                string filePath = Path.Combine(
                   Server.MapPath("~/Images/TabGalleryService"),
                   Path.GetFileName(filename)
               );
                Picture.SaveAs(filePath);
                WebImage img = new WebImage(Picture.InputStream);
                img.Resize(750, 464, false, false);
                img.Save(filePath);
                System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath("~/Images/TabGalleryService/" + filename));
                System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = (ThumbnailCallback);
                int height = fullSizeImg.Height;
                int width = fullSizeImg.Width;
                if (height > width)
                {
                    height = (height * 190) / width;
                    width = 190;
                }
                else
                {
                    width = (width * 190) / height;
                    height = 190;
                }
                System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero);
                thumbNailImg.Save(Server.MapPath("~/Images/TabGalleryService/thum/") + filename);
                ImageResizer.ImageBuilder.Current.Build(Server.MapPath("~/Images/TabGalleryService/thum/") + filename, Server.MapPath("~/Images/TabGalleryService/thum/") + filename, new ImageResizer.ResizeSettings(190, 190, ImageResizer.FitMode.Crop, ""));
                thumbNailImg.Dispose();
                fullSizeImg.Dispose();

            }

            return filename;
        }
        public static int UploadImage(System.Web.HttpPostedFile ImageFile, string strServerImagesDirectoryName)
        {
            if (ImageFile == null)
                throw new FileUploadException("File upload appear to be null!");

            if (ImageFile.FileName == null)
                throw new FileUploadException("File name apear to be null!");

            // FileName -> Only File Name
            // DirectoryName -> Only Directory Name
            // Path -> DirectoryName + FileName

            string strImageFileName = System.IO.Path.GetFileName(ImageFile.FileName);

            string strServerImagePath = strServerImagesDirectoryName + "\\" + strImageFileName;

            if (System.IO.File.Exists(strServerImagePath))
            {
                strImageFileName = System.IO.Path.GetRandomFileName();
                strImageFileName = System.IO.Path.GetFileNameWithoutExtension(strImageFileName);
                strImageFileName += System.IO.Path.GetExtension(strServerImagePath);
                strServerImagePath = strServerImagesDirectoryName + "\\" + strImageFileName;
            }

            //if (!System.IO.Directory.Exists(strPath))
            //{
            //    System.IO.Directory.CreateDirectory(strPath);
            //}

            //if (System.IO.Path.GetExtension(strServerImagePath).ToUpper() != ".JPG" &&
            //    System.IO.Path.GetExtension(strServerImagePath).ToUpper() != ".JPEG")
            //    throw new CustomException();

            //if (ImageFile.ContentType.ToUpper() != "IMAGE/JPEG" /*Firefox*/ &&
            //    ImageFile.ContentType.ToUpper() != "IMAGE/PJPEG" /*Internet Explorer*/)
            //    throw new CustomException();

            if (ImageFile.ContentLength == 0)
                throw new CustomException();

            ConferenceDataSet.ImagesDataTable Images = new ConferenceDataSet.ImagesDataTable();
            ConferenceDataSet.ImagesRow Image = Images.NewImagesRow();

            Image.ClientFileName = ImageFile.FileName;
            Image.FileExtension = System.IO.Path.GetExtension(ImageFile.FileName);
            Image.ContentType = ImageFile.ContentType;
            Image.ContentLength = ImageFile.ContentLength;
            Image.ServerFileName = strImageFileName;

            //if (pfCoverImage.ContentLength > 200 * 1024)
            //{
            //    lblMessage.Visible = true;
            //    lblMessage.ForeColor = System.Drawing.Color.Red;
            //    lblMessage.Text = "Your Picture File Size Must Be Less Than 20 KB.";
            //}
            //else
            //{
            //    System.Drawing.Image img = System.Drawing.Image.FromStream(pfCoverImage.InputStream);
            //    if (img.Width > 1200 || img.Height > 1200)
            //    {
            //        lblMessage.Visible = true;
            //        lblMessage.ForeColor = System.Drawing.Color.Red;
            //        lblMessage.Text = "Your Picture Width & Height Must Be Less Than 120 px.";
            //    }
            //    else
            //    {
            //System.IO.Path.GetTempFileName

            try
            {
                System.Drawing.Image imgCoverImage = System.Drawing.Image.FromStream(ImageFile.InputStream);
                string strMimeType = Conference.GeneralPorpose.GetMimeType(imgCoverImage);
                Image.ContentTypeByCode = strMimeType;
                Image.ImageFormat = imgCoverImage.RawFormat.Guid;
            }
            catch (System.ArgumentException eArgumentException)
            {
                throw new InvalidImageArgumentException(eArgumentException.Message + " Invalid image type!");
            }

            try
            {
                ImageFile.SaveAs(strServerImagePath);
            }
            catch (System.IO.DirectoryNotFoundException eDirectoryNotFound)
            {
            }
            catch (System.UnauthorizedAccessException eUnauthorizedAccess)
            {
            }

            Images.Rows.Add(Image);
            ConferenceDataSetTableAdapters.ImagesTableAdapter ImagesTableAdapter = new ConferenceDataSetTableAdapters.ImagesTableAdapter();
            ImagesTableAdapter.Update(Images);

            return Image.ImageID;
        }
Exemplo n.º 16
0
        private static bool WriteFileToPath(string saveLocation, System.Web.HttpPostedFileBase file)
        {
            bool result = true;

            try
            {
                if (file != null)
                {
                    if (Directory.Exists(Path.GetDirectoryName(saveLocation)) == false)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(saveLocation));
                    }
                    file.SaveAs(saveLocation);
                }
            }
            catch (Exception ex)
            {
                EventLog.LogEvent(ex);
                result = false;
            }

            return result;
        }
Exemplo n.º 17
0
        public static string SaveFileLocally(System.Web.HttpPostedFileBase sourceFile)
        {
            if (!Directory.Exists(LocalTempDestinationPath))
            {
                Directory.CreateDirectory(LocalTempDestinationPath);
            }

            var localFile = Path.Combine(LocalTempDestinationPath, sourceFile.FileName);

            if (!File.Exists(localFile))
            {
                sourceFile.SaveAs(localFile);
            }

            return localFile;
        }
Exemplo n.º 18
0
 public static DataTable LoadFile(System.Web.UI.WebControls.FileUpload fileUpLoad)
 {
     string path = DataAccRes.AppSettings("DefaultFilePath");
     if (string.IsNullOrEmpty(path))
         path = "~/DataSource/upload/";
     if (!path.StartsWith("~/"))
     {
         if (path.StartsWith("/"))
             path = "~" + path;
         else
             path = "~/" + path;
     }
     string IsXls = System.IO.Path.GetExtension(fileUpLoad.FileName).ToString().ToLower();
     string fileName = fileUpLoad.FileName; 
     string serverPath = fileUpLoad.Page.Server.MapPath(path + fileName);
     fileUpLoad.SaveAs(serverPath);
     DataSet ds = ExecleDs(serverPath, fileName, IsXls);
     return ds.Tables[0];
 }
        public ActionResult UploadTest(System.Web.HttpPostedFileBase file)
        {
            if (file == null)
            {
                this.ViewBag.Message = "No file selected";
                return this.View();
            }

            string uploadPath = this.Server.MapPath(Consts.UploadPath);
            if (!System.IO.Directory.Exists(uploadPath))
            {
                System.IO.Directory.CreateDirectory(uploadPath);
            }

            file.SaveAs(string.Format("{0}\\{1}", uploadPath, file.FileName));
            this.ViewBag.Message = "Upload OK";
            return this.View();
        }
Exemplo n.º 20
0
 //#endregion
 //#region 上传文件
 /// <summary>
 /// 上传文件
 /// </summary>
 /// <param name="fileUpload">fileUpload组件</param>
 public void DoUpLoad(System.Web.UI.WebControls.FileUpload fileUpload) {
     string __filePath = HttpContext.Current.Server.MapPath(_filePath);
     if (!System.IO.Directory.Exists(__filePath)) {
         if (_isCreateFolderForNotExits) {
             FileDirectory.DirectoryVirtualCreate(_filePath);
         } else { _State = 3; return; }
     }
     if (fileUpload.PostedFile.ContentLength / 1024 > _maxFileSize) { _State = 4; return; }
     string randStr = "";
     switch (_RandFileType) {
         case RandFileType.None: randStr = ""; break;
         case RandFileType.FileName_DateTime: randStr = "_" + Rand.RndDateStr(); break;
         case RandFileType.FileName_RandNumber: randStr = "_" + Rand.RndCode(_RandNumbers); break;
         case RandFileType.DateTime: randStr = Rand.RndDateStr(); break;
     }
     bool isTrue = false;
     if (fileUpload.HasFile) {
         string _fileExt = System.IO.Path.GetExtension(fileUpload.FileName).ToLower();
         string[] _allowedExt = _allowedExtensions.Split(new string[] { "|" }, StringSplitOptions.None);
         for (int i = 0; i < _allowedExt.Length; i++) {
             if (_fileExt == _allowedExt[i]) { isTrue = true; }
         }
         if (isTrue) {
             try {
                 string fNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fileUpload.FileName);
                 if (_RandFileType == RandFileType.DateTime) fNameNoExt = "";
                 fileUpload.SaveAs(__filePath + fNameNoExt + randStr + System.IO.Path.GetExtension(fileUpload.FileName));
                 _State = 0;
                 _fileSize = fileUpload.PostedFile.ContentLength / 1024;
                 _fileName = _filePath + fNameNoExt + randStr + System.IO.Path.GetExtension(fileUpload.FileName);
             } catch { _State = 2; }
         } else { _State = 1; }
     } else { _State = 2; }
 }
Exemplo n.º 21
0
 public ActionResult Upload(System.Web.HttpPostedFileBase file)
 {
     string filename = Server.MapPath("~/files/somename.ext");
     file.SaveAs(filename);
     return RedirectToAction("Index");
 }
Exemplo n.º 22
0
    public static string UploadImage(System.Web.HttpPostedFile postedFile, int maxSize, string folderName)
    {
        List<string> AllowedFileTypes = new List<string>() { ".jpg", ".jpeg", ".gif", ".png", ".bmp" };

        if (postedFile.ContentLength <= maxSize * 1048576)
        {
            string strFileType = Path.GetExtension(postedFile.FileName).ToLower();

            if (AllowedFileTypes.Contains(strFileType))
            {
                try
                {
                    string strNewFileName = HMAC_MD5(string.Empty, postedFile.FileName + DateTime.Now.ToLongTimeString()) + strFileType;
                    postedFile.SaveAs(folderName + strNewFileName);

                    return strNewFileName;
                }
                catch { return "Error-3"; }
            } return "Error-2";
        } return "Error-1";
    }
Exemplo n.º 23
0
    public bool uploadImageFile(ref System.Web.UI.WebControls.FileUpload fu)
    {
        bool result = false;
        string fn = fu.FileName;
        string uploadedFile = uploadPath + @"\" + fn;
        try
        {
            if (fu.HasFile)
            {
                fu.SaveAs(uploadedFile);
                // jpg to png conversion
                System.Drawing.Image img = System.Drawing.Image.FromFile(uploadedFile);
                img.Save(uploadedFile.Replace(".txt", "pdf"), System.Drawing.Imaging.ImageFormat.Png);
                result = true;
            }

        }
        catch (Exception)
        {
            result = false;
            throw;
        }
        _context.Session["fileName"] = fu.FileName;

        return result;
    }
Exemplo n.º 24
0
 public static void Upload(System.Web.HttpPostedFile file)
 {
     var guid = Guid.NewGuid().ToString().ToUpper();
     file.SaveAs(StoragePath + guid);
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@GUID", SqlIntegrate.DataType.VarChar, guid);
     si.AddParameter("@name", SqlIntegrate.DataType.VarChar,
         Path.GetFileNameWithoutExtension(file.FileName), 50);
     si.AddParameter("@extension", SqlIntegrate.DataType.VarChar,
         Path.GetExtension(file.FileName).TrimStart('.').ToLower(), 10);
     si.AddParameter("@size", SqlIntegrate.DataType.Int, file.ContentLength);
     si.AddParameter("@UUID", SqlIntegrate.DataType.VarChar, User.Current.UUID);
     si.Execute("INSERT INTO [File] ([GUID],[name],[extension],[size],[uploader]) VALUES (@GUID,@name,@extension,@size,@UUID)");
 }
Exemplo n.º 25
0
        public string SaveCV(System.Web.HttpPostedFileBase cvfile)
        {
            var folder = HttpContext.Current.Server.MapPath(FileFolder);
            if (System.IO.Directory.Exists(folder) == false)
            {
                System.IO.Directory.CreateDirectory(folder);
            }

            //TODO: kiểm tra file hợp lệ

            //Save file
            var fileName = Guid.NewGuid().ToString();
            cvfile.SaveAs(System.IO.Path.Combine(folder, cvfile.FileName));
            return cvfile.FileName;
        }
Exemplo n.º 26
0
 public static object[] UploadImageS(System.Web.UI.WebControls.FileUpload upFile, string _ServerPath)
 {
     object[] rtn = new object[] { 1, "", "", "" }; //0成功1失败
     string fileName = upFile.FileName;
     string ext = fileName.Substring(fileName.LastIndexOf("."));
     fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
     fileName = fileName.Substring(0, fileName.LastIndexOf('.')) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
     string S = fileName + "_S" + ext;
     fileName = fileName + "_" + ext;
     string ServerPath = HttpContext.Current.Server.MapPath(_ServerPath);
     if (!System.IO.Directory.Exists(ServerPath))
         System.IO.Directory.CreateDirectory(ServerPath);
     if (upFile.HasFile)
         upFile.SaveAs(ServerPath + fileName);
     try
     {
         App_Com.ImageHelper.MakeThumbnail(ServerPath + fileName, ServerPath + S, 200, 150, "W", App_Com.Helper.GetCompanyName(), "RB", 10);
         rtn[0] = 0;
         rtn[1] = _ServerPath + S;
     }
     catch (Exception ex)
     {
         string ss = ex.Message;
     }
     finally
     {
         if (System.IO.File.Exists(ServerPath + fileName)) { System.IO.File.Delete(ServerPath + fileName); }
     }
     return rtn;
 }
        public ArrayList FileUpload(string s_UploadPath, System.Web.UI.WebControls.FileUpload File_Upload1, string s_LoginUser)
        {
            #region
            String s_fileExtension = string.Empty;//副檔名

            String s_fileWithoutExtension = string.Empty;//檔名不包含副檔名
            DateTime d_CreateDate = DateTime.Now;
            ArrayList arl_Return = new ArrayList();
            bool b_fileOK = false;

            # region 檢查上傳檔案的路徑與檔案格式


            s_fileExtension = System.IO.Path.GetExtension(File_Upload1.FileName).ToLower();//副檔名

            s_fileWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(File_Upload1.FileName).ToLower();//檔名

            if (File_Upload1.HasFile)
            {
                String[] allowedExtensions ={ ".xls" };//在此設定允許上傳的檔案格式


                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (s_fileExtension == allowedExtensions[i])
                    {
                        b_fileOK = true;
                    }
                }
            }
            #endregion

            #region 將檔案上傳至AP

            if (b_fileOK == true)
            {
                s_UploadPath += s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension;
                File_Upload1.SaveAs(s_UploadPath);


                arl_Return.Add("TRUE");
                arl_Return.Add(s_UploadPath);
                arl_Return.Add(d_CreateDate);
                arl_Return.Add(s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension);
            }
            else
            {
                arl_Return.Add("FALSE");
                arl_Return.Add("上傳檔案不是Excel檔");
            }

            #endregion

            return arl_Return;
            #endregion
        }
Exemplo n.º 28
0
 public ContentResult Upload(System.Web.HttpPostedFileBase FileData, string folder)
 {
     string fileName = "";
     if (null != FileData)
     {
         try
         {
             fileName = Path.GetFileName(FileData.FileName);//获得文件名
             string ext = Path.GetExtension(FileData.FileName);//获得文件扩展名
             string processInstID = Request.Form["processInstID"];
             string saveName = Request.Form["name"] + "$" + fileName; //实际保存文件名
             string path = System.Configuration.ConfigurationManager.AppSettings["FileDirectory"];
             string filePath = Request.MapPath(path + "/Workflow/");
             if (!Directory.Exists(filePath))
             {
                 Directory.CreateDirectory(filePath);
             }
             FileData.SaveAs(filePath + saveName);
             UploadFile uploadFile = new UploadFile()
             {
                 ID = IdGenerator.NewGuid().ToSafeString(),
                 UniqueName = saveName,
                 FileName = fileName,
                 CreateTime = DateTime.Now,
                 FilePath = path + "/Workflow/" + saveName,
                 FileType = 0,
                 Creator = workContext.User.ID,
                 BizID = processInstID
             };
             repository.SaveOrUpdate(uploadFile);
         }
         catch (Exception ex)
         {
             fileName = ex.Message;
         }
     }
     return Content(fileName);
 }
Exemplo n.º 29
0
    public string File_Upload(System.Web.UI.WebControls.FileUpload fp)
    {
        string filepath, folderpath, savepath, folderpathnew, savepathnew;
        folderpath = System.Web.HttpContext.Current.Server.MapPath("Resumes");
        folderpathnew = "~\\Resumes";
        filepath = Path.GetFileName(fp.PostedFile.FileName);
        savepath = folderpath + "\\" + filepath;

        savepathnew = folderpathnew + "\\" + filepath;

        fp.SaveAs(savepath);
        return (savepathnew);
    }
Exemplo n.º 30
0
    public bool SaveAttach(System.Web.HttpPostedFile attach)
    {
        string Formname = RandomString(5, true);

        if (attach != null) {
            _Name = System.Text.RegularExpressions.Regex.Replace(attach.FileName, "^.*[/\\\\]", "");
            string[] name = attach.FileName.Split('\\');
            if (name.Length > 0)
                _Filename = name[name.Length - 1];

            _Filename = _Filename + "_" + Formname;
            _ContentType = attach.ContentType;
            _Size = attach.ContentLength;
            if (_Id != 0)
                Save();
            else
                Create();
            attach.SaveAs(FullPath());
            return true;
        }
        return false;
    }