Handler/UploadHandler.ashx.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.IO;
using System.Web;
using System.Web.Services;
namespace FileUploadSample.Handler
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class UploadHandler : IHttpHandler
{
/// <summary>
/// 上传文件夹
/// </summary>
private const string UPLOAD_FOLDER = "~/UploadFile/";
public void ProcessRequest(HttpContext context)
{
int resultVal = (int)ReturnVal.Failed;
string filename = "";
try
{
HttpPostedFile myFile = context.Request.Files["fulFile"];
if (myFile != null)
{
if (myFile.InputStream.Length != 0)
{
string originalFileName = Path.GetFileName(myFile.FileName); //原文件名
string newFileName = string.Format("{0}_{1}", Guid.NewGuid(), originalFileName); //新文件名---组成形式: GUID + 下划线 + 原文件名
filename = newFileName;
string fileAbsPath = context.Server.MapPath(UPLOAD_FOLDER) + newFileName; //绝对路径
myFile.SaveAs(fileAbsPath);
resultVal = (int)ReturnVal.Succeed;
}
else
{
resultVal = (int)ReturnVal.FileEmpty;
}
}
else
{
resultVal = (int)ReturnVal.NotSelected;
}
}
catch (Exception)
{
resultVal = (int)ReturnVal.Failed;
}
finally
{
string StrJson = "{\"filename\":\"" + UPLOAD_FOLDER+ filename + "\",\"resultVal\":" + resultVal + "}";
context.Response.Write(StrJson);
}
}
后面还有 38 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
