-
Notifications
You must be signed in to change notification settings - Fork 0
/
UploadCS.ashx.cs
112 lines (91 loc) · 4.14 KB
/
UploadCS.ashx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Text;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Text.RegularExpressions;
namespace BoardHunt
{
/// <summary>
/// Summary description for UploadCS
/// </summary>
public class UploadCS : IHttpHandler, IRequiresSessionState
{
public static ArrayList filenewname = new ArrayList();
public static ArrayList filenewpath = new ArrayList();
public void ProcessRequest(HttpContext context)
{
string savepath = "";
try
{
List<HttpPostedFile> files = (List<HttpPostedFile>)context.Session["Files"];
HttpPostedFile postedFile = context.Request.Files["Filedata"];
StringBuilder sb = new StringBuilder();
//savepath = HttpContext.Current.Server.MapPath("");
string filePath = "/TempAddImages/";
//extension = Path.GetExtension(postedFile.FileName);
if (!Directory.Exists(context.Server.MapPath(filePath)))
{
Directory.CreateDirectory(savepath);
}
//Guid.NewGuid().ToString() +
if (context.Request.Files.Count <= 0)
{
context.Response.Write("No file uploaded");
}
else
{
HttpFileCollection uploadedVideoFiles = context.Request.Files;
int count = uploadedVideoFiles.Count;
HttpPostedFile file = context.Request.Files[0];
if (file.ContentLength > 0)
{
double scaleFactor = 0.07;
files = new List<HttpPostedFile>();
string filenames = postedFile.FileName;
string filename = Regex.Replace(filenames, @"\s+", "");
file.SaveAs(context.Server.MapPath(filePath + filename));
string targetPath = context.Server.MapPath(filePath + filename);
//FileStream fs = new FileStream(context.Server.MapPath(filePath + filename), FileMode.Open, FileAccess.Read);
//BinaryReader br = new BinaryReader(fs);
//byte[] image = br.ReadBytes((int)fs.Length);
//br.Close();
//fs.Close();
//MemoryStream stream = new MemoryStream(image);
//System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(stream);
//var newWidth = (int)(UploadedImage.Width * scaleFactor);
//var newHeight = (int)(UploadedImage.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(UploadedImage, imageRectangle);
//thumbnailImg.Save(targetPath, UploadedImage.RawFormat);
context.Response.Write(filename);
context.Response.StatusCode = 200;
files.Add(postedFile);
}
}
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}