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


C# HttpFile.SaveAs方法代码示例

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


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

示例1: 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

示例2: SaveImg

        /// <summary>
        /// 上传图片(自定义保存路径)
        /// </summary>
        /// <param name="uploadPath">保存路径(相对路径)</param>
        /// <param name="postedFile">HttpFile</param>
        /// <param name="picName">图片名称</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static Result SaveImg( String uploadPath, HttpFile postedFile, String picName, int width, int height )
        {
            logger.Info( "uploadPath : " + uploadPath );
            logger.Info( "picName : " + picName );
            Result result = new Result();

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

            String str = PathHelper.Map( uploadPath );
            String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType );
            String filename = Path.Combine( str, str2 );
            try {
                postedFile.SaveAs( filename );
                Img.SaveThumbnail( filename, Img.GetThumbPath( filename ), width, height, SaveThumbnailMode.Cut );
            }
            catch (Exception exception) {
                logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
                result.Add( lang.get( "exPhotoUploadErrorTip" ) );
                return result;
            }
            result.Info = Path.GetFileName( Img.GetThumbPath( filename ) );
            return result;
        }
开发者ID:robin88,项目名称:wojilu,代码行数:33,代码来源:Uploader.cs

示例3: SaveFile

        /// <summary>
        /// 保存上传的非图片型文件
        /// </summary>
        /// <param name="postedFile"></param>
        /// <returns></returns>
        public static Result SaveFile( HttpFile postedFile )
        {
            Result errors = new Result();

            checkUploadFile( postedFile, errors );
            if (errors.HasErrors) {
                logger.Info( errors.ErrorsText );
                return errors;
            }

            String fileExt = Path.GetExtension( postedFile.FileName );

            String pathName = PathHelper.Map( sys.Path.DiskPhoto );
            String fileName = Img.GetFileName( pathName, fileExt );
            String filenameWithPath = Path.Combine( pathName, fileName );
            try {
                postedFile.SaveAs( filenameWithPath );
            }
            catch (Exception exception) {
                logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
                errors.Add( lang.get( "exPhotoUploadErrorTip" ) );
                return errors;
            }
            errors.Info = fileName.Replace( @"\", "/" );
            return errors;
        }
开发者ID:robin88,项目名称:wojilu,代码行数:31,代码来源:Uploader.cs

示例4: SaveImg

        /// <summary>
        /// 上传图片(自定义保存路径),同时生成最小的缩略图
        /// </summary>
        /// <param name="uploadPath">保存路径(相对路径)</param>
        /// <param name="postedFile">HttpFile</param>
        /// <param name="picName">图片名称</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static Result SaveImg( String uploadPath, HttpFile postedFile, String picName, int width, int height, SaveThumbnailMode mode )
        {
            logger.Info( "uploadPath : " + uploadPath );
            logger.Info( "picName : " + picName );
            Result result = new Result();

            CheckUploadPic( postedFile, result );
            if (result.HasErrors) return result;

            String str = PathHelper.Map( uploadPath );
            String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType );
            String filename = Path.Combine( str, str2 );
            try {

                String oldFile = null;
                if (file.Exists( filename )) {
                    oldFile = filename + "." + Guid.NewGuid() + Path.GetExtension( filename );
                    file.Move( filename, oldFile );
                }

                postedFile.SaveAs( filename );

                try {
                    saveThumbImagePrivate( filename, ThumbnailType.Small, width, height, mode );

                    if (strUtil.HasText( oldFile )) {
                        file.Delete( oldFile );
                    }
                }
                catch (OutOfMemoryException ex) {

                    file.Delete( filename );
                    if (strUtil.HasText( oldFile )) {
                        file.Move( oldFile, filename );
                    }

                    String msg = "file format error: " + picName;
                    logger.Error( msg );
                    result.Add( msg );
                    return result;
                }

            }
            catch (Exception exception) {
                logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
                result.Add( lang.get( "exPhotoUploadErrorTip" ) );
                return result;
            }
            result.Info = Path.GetFileName( Img.GetThumbPath( filename ) );
            return result;
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:60,代码来源:Uploader.cs

示例5: 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


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