當前位置: 首頁>>代碼示例>>C#>>正文


C# Web.HttpPostedFile類代碼示例

本文整理匯總了C#中System.Web.HttpPostedFile的典型用法代碼示例。如果您正苦於以下問題:C# HttpPostedFile類的具體用法?C# HttpPostedFile怎麽用?C# HttpPostedFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpPostedFile類屬於System.Web命名空間,在下文中一共展示了HttpPostedFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessFile

        public override void ProcessFile(HttpPostedFile file)
        {
            ManualResetEvent e = HttpContext.Current.Items["SyncUploadStorageAdapter"] as ManualResetEvent;

            try
            {
                UploadedFile item = UploadStorageService.CreateFile4Storage(file.ContentType);

                item.FileName = Path.GetFileName(file.FileName);
                item.ContentLength = file.ContentLength;
                item.InputStream = file.InputStream;

                if (!string.IsNullOrEmpty(HttpContext.Current.Request.Form["sectionId"]))
                {
                    Section section = Section.Load(new Guid(HttpContext.Current.Request.Form["sectionId"]));

                    if (section != null)
                        section.AddFile(item);
                }

                item.AcceptChanges();

                HttpContext.Current.Items["fileId"] = item.ID;
            }
            finally
            {
                if (e != null)
                {
                    Trace.WriteLine(string.Format("Signaling event for file in section {0}.", HttpContext.Current.Request.Form["sectionId"]));
                    e.Set();
                }
            }
        }
開發者ID:kohku,項目名稱:codefactory,代碼行數:33,代碼來源:UploadStorageAdapter.cs

示例2: CheckUploadByTwoByte

        /// <summary>
        /// 根據文件的前2個字節進行判斷文件類型  ---說明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
        /// </summary>
        /// <param name="hpf"></param>
        /// <param name="code">文件的前2個字節轉化出來的小數</param>
        /// <returns></returns>
        public bool CheckUploadByTwoByte(HttpPostedFile hpf, Int64 code)
        {
            System.IO.FileStream fs = new System.IO.FileStream(hpf.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
            string fileclass = "";
            byte buffer;
            try
            {
                buffer = r.ReadByte();
                fileclass = buffer.ToString();
                buffer = r.ReadByte();
                fileclass += buffer.ToString();

            }
            catch
            {

            }
            r.Close();
            fs.Close();
            //
            //if (fileclass == code.ToString())
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
            return (fileclass == code.ToString());
        }
開發者ID:cj1324,項目名稱:hanchenproject,代碼行數:37,代碼來源:UploadHelper.cs

示例3: GetFileBytes

 /// <summary>
 /// Gets the file bytes
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="uploadedFile">The uploaded file.</param>
 /// <returns></returns>
 public virtual byte[] GetFileBytes( HttpContext context, HttpPostedFile uploadedFile )
 {
     // NOTE: GetFileBytes can get overridden by a child class (ImageUploader.ashx.cs for example)
     var bytes = new byte[uploadedFile.ContentLength];
     uploadedFile.InputStream.Read( bytes, 0, uploadedFile.ContentLength );
     return bytes;
 }
開發者ID:CentralAZ,項目名稱:Rockit-CentralAZ,代碼行數:13,代碼來源:FileUploader.ashx.cs

示例4: AddFileToSession

        public void AddFileToSession(string controlId, string filename, HttpPostedFile fileUpload)
        {
            if (fileUpload == null)
            {
                throw new ArgumentNullException("fileUpload");
            }
            else if (controlId == String.Empty)
            {
                throw new ArgumentNullException("controlId");
            }

            HttpContext currentContext = null;
            if ((currentContext = GetCurrentContext()) != null)
            {
                var mode = currentContext.Session.Mode;
                if (mode != SessionStateMode.InProc) {
            #if NET4
                    throw new InvalidOperationException(Resources_NET4.SessionStateOutOfProcessNotSupported);
            #else
                    throw new InvalidOperationException(Resources.SessionStateOutOfProcessNotSupported);
            #endif
                }
                currentContext.Session.Add(GetFullID(controlId), fileUpload);
            }
        }
開發者ID:sumutcan,項目名稱:WTWP-Ticket-Booking,代碼行數:25,代碼來源:PersistedStoreManager.cs

示例5: DescribePostedFile

        internal static string DescribePostedFile(HttpPostedFile file)
        {
            if (file.ContentLength == 0 && string.IsNullOrEmpty(file.FileName))
                return "[empty]";

            return string.Format("{0} ({1}, {2} bytes)", file.FileName, file.ContentType, file.ContentLength);
        }
開發者ID:nover,項目名稱:RollbarSharp,代碼行數:7,代碼來源:RequestModelBuilder.cs

示例6: UnpackToFile

 /// <summary>
 ///     Unpacks to file.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="file">The file.</param>
 private static void UnpackToFile(UploadArgs args, HttpPostedFile file)
 {
     Assert.ArgumentNotNull(args, "args");
     Assert.ArgumentNotNull(file, "file");
     var filename = FileUtil.MapPath(TempFolder.GetFilename("temp.zip"));
     file.SaveAs(filename);
     using (var zipReader = new ZipReader(filename))
     {
         foreach (var zipEntry in zipReader.Entries)
         {
             var str = FileUtil.MakePath(args.Folder, zipEntry.Name, '\\');
             if (zipEntry.IsDirectory)
             {
                 Directory.CreateDirectory(str);
             }
             else
             {
                 if (!args.Overwrite)
                     str = FileUtil.GetUniqueFilename(str);
                 Directory.CreateDirectory(Path.GetDirectoryName(str));
                 lock (FileUtil.GetFileLock(str))
                     FileUtil.CreateFile(str, zipEntry.GetStream(), true);
             }
         }
     }
 }
開發者ID:raynjamin,項目名稱:Sitecore-S3-Media,代碼行數:31,代碼來源:SaveImagesToS3.cs

示例7: SaveProductMainImage

        public static bool SaveProductMainImage(int ProductID, HttpPostedFile OriginalFile, out string[] FileNames)
        {
            string FileSuffix = Path.GetExtension(OriginalFile.FileName).Substring(1);
            bool ProcessResult = false;
            FileNames = GetMainImageName(ProductID, FileSuffix);
            if (!Directory.Exists(config.PathRoot)) Directory.CreateDirectory(config.PathRoot);

            if (config.AllowedFormat.ToLower().Contains(FileSuffix.ToLower()) && config.MaxSize * 1024 >= OriginalFile.ContentLength)
            {
                ImageHelper ih = new ImageHelper();

                ih.LoadImage(OriginalFile.InputStream);

                for (int i = 2; i >= 0; i--)
                {
                    if (config.ImageSets[i].Width > 0 && config.ImageSets[i].Height > 0)
                    {
                        ih.ScaleImageByFixSize(config.ImageSets[i].Width, config.ImageSets[i].Height, true);
                    }
                    ih.SaveImage(config.PathRoot + FileNames[i]);
                }

                ih.Dispose();
                //foreach (string FileName in FileNames)
                //{
                //    //縮小圖片為設置尺寸注意圖片尺寸與名稱對應
                //    OriginalFile.SaveAs(config.PathRoot + FileName);
                //}

                ProcessResult = true;
            }

            return ProcessResult;
        }
開發者ID:ViniciusConsultor,項目名稱:noname-netshop,代碼行數:34,代碼來源:MagicWorldImageRule.cs

示例8: AddImage

        public ActionResult AddImage(HttpPostedFile uploadFile, int eventID)
        {
            string[] all = Request.Files.AllKeys;

            foreach (string file in Request.Files.AllKeys)
            {
                HttpPostedFileBase hpf = Request.Files[file];
                if (hpf.ContentLength == 0)
                    continue;
                else
                {
                    var fileName = DateTime.Now.Ticks + Path.GetFileName(hpf.FileName);
                    var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Images/uploads/", fileName);
                    uploadFile.SaveAs(path);
                }
            }

            ViewData["UploadSucceed"] = "Image upload succeded";
            return RedirectToAction("ShowImages", new { eventID = eventID });

            //if (uploadFile.ContentLength > 0)
            //{
            //    var fileName = DateTime.Now.Ticks + Path.GetFileName(uploadFile.FileName);
            //    var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Images/uploads/", fileName);
            //    uploadFile.SaveAs(path);
            //    ViewData["UploadSucceed"] = "Image upload succeded";
            //    return RedirectToAction("ShowImages", new { eventID = eventID });
            //}
            //else
            //{
            //    ViewBag.UploadError = "";
            //    return View();
            //}
        }
開發者ID:uczenn,項目名稱:Blog,代碼行數:34,代碼來源:ImageController.cs

示例9: PostedFile

		public PostedFile(HttpPostedFile httpPostedFile)
		{
			_fileName = httpPostedFile.FileName;
			_stream = httpPostedFile.InputStream;
			_contentType = httpPostedFile.ContentType;
			_length = httpPostedFile.ContentLength;
		}
開發者ID:kendarorg,項目名稱:Node.Cs.Old,代碼行數:7,代碼來源:PostedFile.cs

示例10: MemoryStreamSmall

        void MemoryStreamSmall(HttpPostedFile hpFile, string name, string type, int Width, int Height)
        {
            Image img = Image.FromStream(hpFile.InputStream);
            Bitmap bit = new Bitmap(img);

            if (bit.Width > Width || bit.Height > Height)
            {

                int desiredHeight = bit.Height;

                int desiredWidth = bit.Width;

                double heightRatio = (double)desiredHeight / desiredWidth;

                double widthRatio = (double)desiredWidth / desiredHeight;


                if (heightRatio > 1)
                {
                    Width = Convert.ToInt32(Height * widthRatio);
                }
                else
                {
                    Height = Convert.ToInt32(Width * heightRatio);
                }

                bit = new Bitmap(bit, Width, Height);//圖片縮放
            }

            bit.Save(name.Substring(0, name.LastIndexOf('.')) + "A." + type, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
開發者ID:BlueZore,項目名稱:ImageGroupUpload,代碼行數:31,代碼來源:UploadHandler.ashx.cs

示例11: GenerateVersions

        //temp
        public bool GenerateVersions(HttpPostedFile file, string leafDirectoryName, string origFileName)
        {
            Dictionary<string, string> versions = new Dictionary<string, string>();
            //Define the version to generate
            versions.Add("_thumb", "width=100&height=100&crop=auto&format=jpg"); //Crop to square thumbnail
            versions.Add("_medium", "maxwidth=400&maxheight=400format=jpg"); //Fit inside 400x400 area, jpeg

            //Loop through each uploaded file
            foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
            {
                if (file.ContentLength <= 0) continue; //Skip unused file controls.
                var uploadFolder = GetPhysicalPathForFile(file, leafDirectoryName);
                if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder);
                //Generate each version
                string[] spFiles = origFileName.Split('.');
                foreach (string suffix in versions.Keys)
                {
                    string appndFileName = spFiles[0] + suffix;
                    string fileName = Path.Combine(uploadFolder, appndFileName);
                    fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false,
                                                          true);
                }

            }
            return true;
        }
開發者ID:reharik,項目名稱:MethodFitness,代碼行數:27,代碼來源:IFileHandlerService.cs

示例12: SaveAs

 protected override void SaveAs(string uploadPath, string fileName, HttpPostedFile file)
 {
     file.SaveAs(uploadPath + fileName);
     ImageTools.MakeThumbnail(uploadPath + fileName, uploadPath + "T32X32_" + fileName, 0x20, 0x20, MakeThumbnailMode.HW, InterpolationMode.High, SmoothingMode.HighQuality);
     ImageTools.MakeThumbnail(uploadPath + fileName, uploadPath + "T130X130_" + fileName, 130, 130, MakeThumbnailMode.HW, InterpolationMode.High, SmoothingMode.HighQuality);
     ImageTools.MakeThumbnail(uploadPath + fileName, uploadPath + "T300X390_" + fileName, 300, 390, MakeThumbnailMode.Cut, InterpolationMode.High, SmoothingMode.HighQuality);
 }
開發者ID:huaminglee,項目名稱:myyyyshop,代碼行數:7,代碼來源:ProductSkuImgHandler.cs

示例13: SavePhoto

 public string SavePhoto(HttpPostedFile imageFile)
 {
     var path = @"~/Images/users_pic";
     var filename = string.Format("{0}/{1}", path, imageFile.FileName);
     imageFile.SaveAs(System.Web.Hosting.HostingEnvironment.MapPath(filename));
     return filename;
 }
開發者ID:pasha369,項目名稱:RestaurantManagementSystem,代碼行數:7,代碼來源:ImageController.cs

示例14: SaveAspect

        public override ImagePreviewDTO SaveAspect(HttpPostedFile file)
        {
            ImagePreviewDTO previewDTO = base.SaveAspect(file);
            string Folder_60X60 = string.Format("{0}\\60X60", this.FolderServerPath);
            string Folder_120X120 = string.Format("{0}\\120X120", this.FolderServerPath);

            if (!System.IO.Directory.Exists(Folder_60X60))
            {
                System.IO.Directory.CreateDirectory(Folder_60X60);
            }
            if (!System.IO.Directory.Exists(Folder_120X120))
            {
                System.IO.Directory.CreateDirectory(Folder_120X120);
            }

            string fileName_60X60 = string.Format(Folder_60X60 + "\\{0}", previewDTO.FileName);
            string fileName_120X120 = string.Format(Folder_120X120 + "\\{0}", previewDTO.FileName);
            string orignalFilePath = string.Format(this.OrignalImageServerPath + "\\{0}", previewDTO.FileName);
            //自己需要使用的尺寸
            IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalFilePath, fileName_60X60, 60, 60, "AHW");
            IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalFilePath, fileName_120X120, 120, 120, "AHW");
            CompanyImagePreviewDTO companyPreviewDTO = new CompanyImagePreviewDTO(previewDTO);
            companyPreviewDTO.Image_60X60 = string.Format("{0}/60X60/{1}", this.FolderPath, previewDTO.FileName);
            companyPreviewDTO.Image_120X120 = string.Format("{0}/120X120/{1}", this.FolderPath, previewDTO.FileName);
            return companyPreviewDTO;
        }
開發者ID:AllanHao,項目名稱:WebSystem,代碼行數:26,代碼來源:CompanyImageAspect.cs

示例15: CreateBllImage

 public static byte[] CreateBllImage(HttpPostedFile loadImage)
 {
     var image = new byte[loadImage.ContentLength];
     loadImage.InputStream.Read(image, 0, loadImage.ContentLength);
     loadImage.InputStream.Close();
     return image;
 }
開發者ID:kinderswan,項目名稱:BriefList,代碼行數:7,代碼來源:Image.cs


注:本文中的System.Web.HttpPostedFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。