سلام
من برای فایل اپلود یه Handler دارم که موقعی میخوام سایز تصاویر تغییر بدم به مشکل میخورم اما سایز اصلی درست اپلود میکنه
2-بعد به جای کد زیر باید چه کدی بنویسم چون server نمیشناسه
string targetPath = Server.MapPath(paththumbImg) + postedFile.FileName;
اینم کد کامل
using System; using System.Web; using System.IO; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI; using System.Web.UI.WebControls; public class HandlerCS : IHttpHandler { public void ProcessRequest(HttpContext context) { foreach (string key in context.Request.Files) { HttpPostedFile postedFile = context.Request.Files[key]; string folderPath = context.Server.MapPath("~/Cr-Content/image/post/large/"); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } postedFile.SaveAs(folderPath + postedFile.FileName); } //***اپلود سایز کوچک foreach (string key in context.Request.Files) { string paththumbImg = "/Cr-Content/image/post/thumbImg/";//تصویر بند انگشتی برای پنل HttpPostedFile postedFile = context.Request.Files[key]; string Extension = Path.GetExtension(postedFile.FileName); string FileName = postedFile.FileName; Stream strm = postedFile.InputStream; using (var image = System.Drawing.Image.FromStream(strm)) { int newWidth = Convert.ToInt32("150"); // New Width of Image in Pixel int newHeight = Convert.ToInt32("150"); // New Height of Image in Pixel var thumbImg = new Bitmap(newWidth, newHeight); var thumbGraph = Graphics.FromImage(thumbImg); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; var imgRectangle = new Rectangle(0, 0, newWidth, newHeight); thumbGraph.DrawImage(image, imgRectangle); string targetPath = Server.MapPath(paththumbImg) + postedFile.FileName; thumbImg.Save(targetPath, image.RawFormat); } //**پایان } context.Response.StatusCode = 200; context.Response.ContentType = "text/plain"; context.Response.Write("Success"); } public bool IsReusable { get { return false; } } }
متن ارور ؟
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)