资源简介
因为最近开发项目使用,用的asp.net开发。自己写的deom。把文件夹拖入之后。就可以把文件夹内的所有文件都上传。经测试非常完美!已经在生产项目里使用了。自己下载之后可以调试研究。用的framework4.5.开发工具vs2015。都是搞技术的,骗子不得好死。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using EntApp.Common;
using System.IO;
using EntApp.Common.Extension;
using Newtonsoft;
using Newtonsoft.Json;
using StreamAspNet.Common;
namespace StreamAspNet
{
///
/// Upload 的摘要说明
///
public class FileUpload : IHttpHandler
{
HttpRequest _request;
HttpResponse _response;
HttpServerUtility _server;
FileHelper _fileHelper = new FileHelper();
private string _tokenPath = “upload/tokens/“; //令牌保存目录
private string _filePath = “upload/files/“; //上传文件保存目录
public void ProcessRequest(HttpContext context)
{
_request = context.Request;
_response = context.Response;
_server = context.Server;
string method = _request[“Method“].ToString();
MethodInfo methodInfo = GetType().GetMethod(method);
methodInfo.Invoke(this null);
}
public void upload()
{
string token = _request.QueryString[“token“];
UploadToken uploadToken = GetTokenInfo(token);
if(uploadToken!=null && uploadToken.size>uploadToken.upsize)
{
Stream stream = _request.InputStream;
if(stream!=null && stream.Length>0)
{
_fileHelper.FileName = uploadToken.name;
_fileHelper.FilePath = _server.MapPath(_filePath);
_fileHelper.WriteFile(stream);
uploadToken.upsize += stream.Length;
if(uploadToken.size>uploadToken.upsize)
{
SetTokenInfo(token uploadToken);
}
else
{
//上传完成后删除令牌信息
DelTokenInfo(token);
}
}
}
UploadResult ur = new UploadResult();
ur.message = ““;
ur.start = uploadToken.upsize;
ur.success = true;
string result= Jsonhelper.Serializeobject(ur);
_response.Write(result);
}
///
/// 获取令牌
///
public void tk()
{
UploadToken uploadToken = new UploadToken();
string name = _request.QueryString[“name“];
string size = _request.QueryString[“size“];
string ext=name.Substring(name.LastIndexOf(‘.‘));
string token = SimpleEncryptor.MD5(name + size);
uploadToken.name = name;
uploadToken.size = size.ToInt(0);
uploadToken.token = token;
if (!File.Exists(_server.MapPath(_tokenPath+token+“.token“)))
{
string modified = _request.QueryString[“modified“];
uploadToken.filePath = ““;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 227 2015-08-12 18:39 StreamAspNet-master\.gitignore
文件 5 2015-08-12 18:39 StreamAspNet-master\.tfignore
文件 85913 2018-05-06 10:48 StreamAspNet-master\.vs\config\applicationhost.config
..A..H. 37376 2018-05-12 11:36 StreamAspNet-master\.vs\StreamAspNet\v14\.suo
文件 1016 2015-08-12 18:39 StreamAspNet-master\README.md
文件 465408 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\bin\Newtonsoft.Json.dll
文件 18432 2018-05-12 11:35 StreamAspNet-master\StreamAspNet\bin\StreamAspNet.dll
文件 610 2018-05-12 11:35 StreamAspNet-master\StreamAspNet\bin\StreamAspNet.dll.config
文件 52736 2018-05-12 11:35 StreamAspNet-master\StreamAspNet\bin\StreamAspNet.pdb
文件 8182 2018-05-06 11:49 StreamAspNet-master\StreamAspNet\common\FileHelper.cs
文件 2388 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\Json
文件 6487 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\SimpleEncryptor.cs
文件 6650 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\StringExtension.cs
文件 291 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\TokenResult.cs
文件 291 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\UploadResult.cs
文件 438 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\common\UploadToken.cs
文件 1277 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\css\img\bgx.png
文件 3565 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\css\img\upload.gif
文件 3136 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\css\stream-v1.css
文件 99 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\FileUpload.ashx
文件 4800 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\FileUpload.ashx.cs
文件 95 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\Global.asax
文件 327 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\Global.asax.cs
文件 3919 2018-05-12 11:24 StreamAspNet-master\StreamAspNet\index.html
文件 92232 2018-05-12 11:20 StreamAspNet-master\StreamAspNet\js\stream-v1.js
文件 73120 2018-05-12 11:17 StreamAspNet-master\StreamAspNet\js\stream-v1原来的不能大于100个.js
文件 465408 2015-08-12 18:39 StreamAspNet-master\StreamAspNet\lib\Newtonsoft.Json.dll
文件 9161 2018-05-12 11:35 StreamAspNet-master\StreamAspNet\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 747 2018-05-06 11:36 StreamAspNet-master\StreamAspNet\obj\Debug\StreamAspNet.csproj.FileListAbsolute.txt
文件 14881 2018-05-06 11:36 StreamAspNet-master\StreamAspNet\obj\Debug\StreamAspNet.csprojResolveAssemblyReference.cache
............此处省略37个文件信息
- 上一篇:在线考试系统B/S[C#]
- 下一篇:C#版本的基础视频通信
评论
共有 条评论