get-images.ashx

来自「经典编程900例(C语言),主要是C基础知识」· ASHX 代码 · 共 65 行

ASHX
65
字号
<%@ WebHandler Language="C#" Class="get_images" %>

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web.SessionState;
using nStuff.ScriptSharp.Web.RestRpc;

public class get_images : RpcHandler, IReadOnlySessionState
{
	class ImageMsg
	{
		public string _name;
		public int _size;
		public DateTime _lastmod;
		public string _url;
		
		public string name
		{
			get { return _name;}
			set { _name = value; }
		}
		public int size
		{
			get { return _size;}
			set { _size = value; }
		}
		public DateTime lastmod
		{
			get { return _lastmod;}
			set { _lastmod = value; }
		}
		public string url
		{
			get { return _url; }
			set { _url = value; }
		}
	}
	
	[RpcMethod(RpcVerb.Get)]
	public Hashtable Get(string _dc)
	{
		string path = Context.Server.MapPath("./thumbs");
		
		List<ImageMsg> images = new List<ImageMsg>();
		DirectoryInfo di = new DirectoryInfo(path);
		FileInfo[] files = di.GetFiles("*.jpg");
		foreach (FileInfo file in files)
		{
			ImageMsg i = new ImageMsg();
			i.name = file.Name;
			i.lastmod = file.LastWriteTime;
			i.size = (int)file.Length;
			i.url = String.Format("./thumbs/{0}", file.Name);
			
			images.Add(i);
		}

		Hashtable msg = new Hashtable();
		msg["images"] = images.ToArray();
		return msg;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?