当前位置: 首页>>代码示例>>C#>>正文


C# HttpFile类代码示例

本文整理汇总了C#中HttpFile的典型用法代码示例。如果您正苦于以下问题:C# HttpFile类的具体用法?C# HttpFile怎么用?C# HttpFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpFile类属于命名空间,在下文中一共展示了HttpFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkUploadPic

        /// <summary>
        /// 检查上传的图片是否合法
        /// </summary>
        /// <param name="postedFile"></param>
        /// <param name="errors"></param>
        public static void checkUploadPic( HttpFile postedFile, Result errors )
        {
            if (postedFile == null) {
                errors.Add( lang.get( "exPlsUpload" ) );
                return;
            }

            // 检查文件大小
            if (postedFile.ContentLength <= 1) {
                errors.Add( lang.get( "exPlsUpload" ) );
                return;
            }

            int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB;
            if (postedFile.ContentLength > uploadMax) {
                errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" );
                return;
            }

            // TODO: (flash upload) application/octet-stream
            //if (postedFile.ContentType.ToLower().IndexOf( "image" ) < 0) {
            //    errors.Add( lang.get( "exPhotoFormatTip" ) );
            //    return;
            //}

            // 检查文件格式
            if (Uploader.isAllowedPic( postedFile ) == false) {
                errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" );
            }
        }
开发者ID:robin88,项目名称:wojilu,代码行数:35,代码来源:Uploader.cs

示例2: CometWorker_FileUploadRequested

 static void CometWorker_FileUploadRequested(ref HttpFile file)
 {
     string fileName = file.ServerMapPath + "\\Upload\\" + file.FileName;
     file.SaveAs(fileName);
     string resourceName = file.FileName.Replace("&", "_");
     ResourceManager.AddReplaceResource(fileName, resourceName, ResourceType.Image, file.ClientId);
     CometWorker.SendToClient(file.ClientId, JSON.Method("ShowImage", resourceName));
 }
开发者ID:wangchunlei,项目名称:MyGit,代码行数:8,代码来源:Default.aspx.cs

示例3: TestDisposedFilename

		public void TestDisposedFilename()
		{
			HttpFile file = new HttpFile("object", "object", "object");
			file.Dispose();

			#pragma warning disable 168
		    Assert.Throws(typeof (ObjectDisposedException), delegate { string tmp = file.Filename; });
			#pragma warning restore 168
		}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:9,代码来源:HttpFileTest.cs

示例4: TestFileDeletion

		/// <summary> Test to make sure files gets deleted upon disposing </summary>
		public void TestFileDeletion()
		{
			string path = Environment.CurrentDirectory + "\\tmptest";
			HttpFile file = new HttpFile("testFile", path, "nun");

			File.WriteAllText(path, "test");
			file.Dispose();

			Assert.Equal(File.Exists(path), false);
		}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:11,代码来源:HttpFileTest.cs

示例5: TestModifications

		public void TestModifications()
		{
			HttpFile file = new HttpFile("testFile", "nun", "nun");
			_form.AddFile(file);
			Assert.Equal(file, _form.GetFile("testFile"));

			_form.Add("valueName", "value");
			Assert.Equal("value", _form["valueName"].Value);

			_form.Clear();
			Assert.Null(_form.GetFile("testFile"));
			Assert.Null(_form["valueName"].Value);
		}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:13,代码来源:HttpFormTest.cs

示例6: savePostData

        private AttachmentTemp savePostData( HttpFile postedFile, Result result ) {
            // 将附件存入数据库
            AttachmentTemp uploadFile = new AttachmentTemp();
            uploadFile.FileSize = postedFile.ContentLength;
            uploadFile.Type = postedFile.ContentType;
            uploadFile.Name = result.Info.ToString();
            uploadFile.Description = ctx.Post( "FileDescription" );
            uploadFile.ReadPermission = ctx.PostInt( "FileReadPermission" );
            uploadFile.Price = ctx.PostInt( "FilePrice" );
            uploadFile.AppId = ctx.app.Id;

            attachService.CreateTemp( uploadFile, (User)ctx.viewer.obj, ctx.owner.obj );
            return uploadFile;
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:14,代码来源:UploaderController.cs

示例7: IsAllowedPic

        /// <summary>
        /// 是否允许的格式
        /// </summary>
        /// <param name="pfile"></param>
        /// <returns></returns>
        public static Boolean IsAllowedPic( HttpFile pfile )
        {
            String[] types = { "jpg", "gif", "bmp", "png", "jpeg" };
            String[] cfgTypes = config.Instance.Site.UploadPicTypes;
            if (cfgTypes != null && cfgTypes.Length > 0) types = cfgTypes;

            if (containsChar( cfgTypes, "*" )) return true;

            foreach (String ext in types) {
                if (strUtil.IsNullOrEmpty( ext )) continue;
                String extWithDot = ext.StartsWith( "." ) ? ext : "." + ext;
                if (strUtil.EqualsIgnoreCase( Path.GetExtension( pfile.FileName ), extWithDot )) return true;
            }

            return false;
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:21,代码来源:Uploader.cs

示例8: CheckUploadPic

        /// <summary>
        /// 检查上传的图片是否合法
        /// </summary>
        /// <param name="postedFile"></param>
        /// <param name="errors"></param>
        public static void CheckUploadPic( HttpFile postedFile, Result errors )
        {
            if (postedFile == null) {
                errors.Add( lang.get( "exPlsUpload" ) );
                return;
            }

            // 检查文件大小
            if (postedFile.ContentLength <= 1) {
                errors.Add( lang.get( "exPlsUpload" ) );
                return;
            }

            int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB;
            if (postedFile.ContentLength > uploadMax) {
                errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" );
                return;
            }

            // 检查文件格式
            if (Uploader.IsAllowedPic( postedFile ) == false) {
                errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" );
            }
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:29,代码来源:Uploader.cs

示例9: SaveImg

        /// <summary>
        /// 保存上传的图片
        /// </summary>
        /// <param name="postedFile"></param>
        /// <param name="arrThumbType"></param>
        /// <returns></returns>
        public static Result SaveImg( HttpFile postedFile, ThumbnailType[] arrThumbType )
        {
            Result result = new Result();

            checkUploadPic( postedFile, result );
            if (result.HasErrors) {
                logger.Info( result.ErrorsText );
                return result;
            }

            String pathName = PathHelper.Map( sys.Path.DiskPhoto );
            String photoName = Img.GetPhotoName( pathName, postedFile.ContentType );
            String filename = Path.Combine( pathName, photoName );

            try {
                postedFile.SaveAs( filename );

                foreach (ThumbnailType ttype in arrThumbType) {
                    saveThumbSmall( filename, ttype );
                }

            }
            catch (Exception exception) {
                logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
                result.Add( lang.get( "exPhotoUploadErrorTip" ) );
                return result;
            }
            result.Info = photoName.Replace( @"\", "/" );
            return result;
        }
开发者ID:robin88,项目名称:wojilu,代码行数:36,代码来源:Uploader.cs

示例10: SaveGroupLogo

 /// <summary>
 /// 保存群组 logo
 /// </summary>
 /// <param name="postedFile"></param>
 /// <param name="groupUrlName"></param>
 /// <returns></returns>
 public static Result SaveGroupLogo( HttpFile postedFile, String groupUrlName )
 {
     return SaveImg( sys.Path.DiskGroupLogo, postedFile, groupUrlName, config.Instance.Group.LogoWidth, config.Instance.Group.LogoHeight );
 }
开发者ID:robin88,项目名称:wojilu,代码行数:10,代码来源:Uploader.cs

示例11: upload_private

        private static Result upload_private( String uploadPath, HttpFile postedFile, String picName )
        {
            logger.Info( "uploadPath:" + uploadPath + ", picName:" + picName );

            Result result = new Result();

            Uploader.checkUploadPic( postedFile, result );
            if (result.HasErrors) return result;

            String str = PathHelper.Map( uploadPath );
            String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType );
            String srcPath = Path.Combine( str, str2 );
            try {
                postedFile.SaveAs( srcPath );
                saveAvatarThumb( srcPath );
            }
            catch (Exception exception) {
                logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
                result.Add( lang.get( "exPhotoUploadErrorTip" ) );
                return result;
            }

            // 返回的信息是缩略图
            String thumbPath = Img.GetThumbPath( srcPath );
            result.Info = "face/" + Path.GetFileName( thumbPath );
            return result;
        }
开发者ID:robin88,项目名称:wojilu,代码行数:27,代码来源:AvatarUploader.cs

示例12: SaveFileOrImage

        /// <summary>
        /// 保存上传的文件,如果是图片,则处理缩略图
        /// </summary>
        /// <param name="postedFile"></param>
        /// <returns></returns>
        public static Result SaveFileOrImage( HttpFile postedFile )
        {
            if (postedFile == null) {
                return new Result( lang.get( "exPlsUpload" ) );
            }

            if (Uploader.IsImage( postedFile ))
                return Uploader.SaveImg( postedFile );

            return Uploader.SaveFile( postedFile );
        }
开发者ID:robin88,项目名称:wojilu,代码行数:16,代码来源:Uploader.cs

示例13: isAllowedFile

        private static Boolean isAllowedFile( HttpFile pfile )
        {
            String[] types = { "zip", "7z", "rar" };
            String[] cfgTypes = config.Instance.Site.UploadFileTypes;
            if (cfgTypes != null && cfgTypes.Length > 0) types = cfgTypes;

            foreach (String ext in types) {
                if (strUtil.IsNullOrEmpty( ext )) continue;
                String extWithDot = ext.StartsWith( "." ) ? ext : "." + ext;
                if (strUtil.EqualsIgnoreCase( Path.GetExtension( pfile.FileName ), extWithDot )) return true;
            }

            return false;
        }
开发者ID:robin88,项目名称:wojilu,代码行数:14,代码来源:Uploader.cs

示例14: IsImage

 /// <summary>
 /// 判断上传文件是否是图片
 /// </summary>
 /// <param name="postedFile"></param>
 /// <returns></returns>
 public static Boolean IsImage( HttpFile postedFile )
 {
     return IsImage( postedFile.ContentType, postedFile.FileName );
 }
开发者ID:robin88,项目名称:wojilu,代码行数:9,代码来源:Uploader.cs

示例15: Save

 /// <summary>
 /// 保存用户上传的头像
 /// </summary>
 /// <param name="postedFile"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static Result Save( HttpFile postedFile, int userId )
 {
     return upload_private( sys.Path.DiskAvatar, postedFile, userId );
 }
开发者ID:Boshin,项目名称:wojilu,代码行数:10,代码来源:AvatarUploader.cs


注:本文中的HttpFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。