folder copy by coding in folder page also copy in asp.net code
_Fname = FileUpload1.FileName.ToString();
_Path = "../ProductImage/" + _Fname;
// string rep = _Path.Replace("~/", "");
string rep = "ProductImage/" + _Fname;
//FileUpload1.SaveAs(Server.MapPath(_Path));
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string targetPath = Server.MapPath(_Path);
Stream strm = FileUpload1.PostedFile.InputStream;
var targetFile = targetPath;
//Based on scalefactor image size will vary
GenerateThumbnails(0.5, strm, targetFile);
private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
{
using (var image =System.Drawing.Image.FromStream(sourcePath))
{
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}
}
_Path = "../ProductImage/" + _Fname;
// string rep = _Path.Replace("~/", "");
string rep = "ProductImage/" + _Fname;
//FileUpload1.SaveAs(Server.MapPath(_Path));
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string targetPath = Server.MapPath(_Path);
Stream strm = FileUpload1.PostedFile.InputStream;
var targetFile = targetPath;
//Based on scalefactor image size will vary
GenerateThumbnails(0.5, strm, targetFile);
private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
{
using (var image =System.Drawing.Image.FromStream(sourcePath))
{
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}
}
No comments:
Post a Comment