12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Web;
- namespace WWPipeLine.MapWebTools.Tools
- {
-
-
-
- public class PictureUpload : IHttpHandler
- {
- private static string imgUploadDir = System.Configuration.ConfigurationManager.ConnectionStrings["imgUploadDir"].ConnectionString;
- private static string GISversion = System.Configuration.ConfigurationManager.ConnectionStrings["GISversion"].ConnectionString;
- public void ProcessRequest(HttpContext context)
- {
-
-
- string action = context.Request.QueryString["action"];
- switch (action)
- {
- case "UpLoadFile":
- UpLoadFile(context);
- break;
- case "getGISversion":
- {
- context.Response.Write(GISversion);
- context.Response.End();
- }
- break;
- default:
- UpLoadFile(context);
- break;
- }
- }
- private void UpLoadFile(HttpContext context)
- {
- try
- {
- string fileName = context.Request.QueryString["name"];
- if (string.IsNullOrEmpty(fileName))
- {
- context.Response.Write(""); context.Response.End(); return;
- }
- string imgMapPath = context.Server.MapPath(imgUploadDir);
- if (!Directory.Exists(imgMapPath))
- Directory.CreateDirectory(imgMapPath);
- foreach (string f in context.Request.Files.AllKeys)
- {
- HttpPostedFile httpPostedFile = context.Request.Files[f];
- httpPostedFile.SaveAs(imgMapPath + fileName);
- }
- context.Response.Write(imgUploadDir + fileName);
- }
- catch (Exception ex)
- {
- context.Response.Write("");
- }
- finally
- {
- context.Response.End();
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
- }
|