- <wijmo:C1Upload ID="C1Upload1" runat="server" width="300px" Action="UploadHandler.ashx" />
复制代码
UploadHandler.ashx
- public class UploadHandler : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- string sDirectory = HttpContext.Current.Server.MapPath("~/Uploaded");
- if (!Directory.Exists(sDirectory))
- {
- Directory.CreateDirectory(sDirectory);
- }
- var request = context.Request;
- var requestType = request.Headers["Wijmo-RequestType"];
- if (!String.IsNullOrEmpty(requestType) && requestType == "XMLHttpRequest")
- {
- var fileName = request.Headers["Wijmo-FileName"];
- using (FileStream fs = new FileStream(sDirectory + "\" + context.Server.UrlDecode(fileName), FileMode.Create))
- {
- var inputStream = context.Request.InputStream;
- byte[] bytes = new byte[(int)inputStream.Length];
- inputStream.Read(bytes, 0, (int)inputStream.Length);
- fs.Write(bytes, 0, bytes.Length);
- fs.Close();
- }
- }
- else
- {
- HttpFileCollection oFiles = context.Request.Files;
- if (oFiles != null && oFiles.Count > 0)
- {
- for (int i = 0; i < oFiles.Count; i++)
- {
- string fileName = oFiles[i].FileName;
- int idx = fileName.LastIndexOf("\");
- if (idx > -1)
- {
- fileName = fileName.Substring(idx + 1);
- }
- oFiles[i].SaveAs(sDirectory + "\" + fileName);
- }
- context.Response.Write("Sucess");
- }
- else
- {
- context.Response.Write("Fail");
- }
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
复制代码
问题描述:UploadHandler.ashx不起任何作用。。。 |
|