本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}