Web/Helpers/WebFileHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ComLib.Extensions;
namespace ComLib.Web.Helpers
{
/// <summary>
/// Helper class for handling uploaded files.
/// </summary>
public class WebFileHelper
{
/// <summary>
/// Checks if any media files were uploaded by checking the size of each posted file.
/// </summary>
/// <param name="request">Http request.</param>
/// <returns>True if media files were uploaded.</returns>
public static bool HasFiles(HttpRequestBase request)
{
if (request.Files == null || request.Files.Count == 0)
return false;
// Now check if files were uploaded.
for (int ndx = 0; ndx < request.Files.Count; ndx++)
{
var file = request.Files[ndx];
if (file.ContentLength > 0)
return true;
}
return false;
}
/// <summary>
/// Checks if any media files were uploaded by checking the size of each posted file.
/// </summary>
/// <param name="request">Http request.</param>
/// <param name="maxSizeInK">The maximum size of each file.</param>
/// <param name="maxNumFiles">The maximum number of files allowed.</param>
/// <param name="errorStorage">Callback for adding errors</param>
/// <returns>True if media files were uploaded.</returns>
public static bool ValidateMediaFiles(HttpRequestBase request, int maxSizeInK, int maxNumFiles, Action<string, string> errorStorage)
{
// No files ?
if (request.Files == null || request.Files.Count == 0)
return true;
// Max files exceeded?
if (request.Files.Count > maxNumFiles)
{
if (errorStorage != null)
errorStorage("Media files", "No more than " + maxNumFiles + " can be uploaded.");
return false;
}
bool isValid = true;
后面还有 20 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
