uploadattachment.cs

来自「community server 源码」· CS 代码 · 共 61 行

CS
61
字号
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls
{
	public class UploadAttachment : CommunityServer.Controls.UploadAttachment
	{
		private Section _section;
		protected override Section Section
		{
			get
			{
				if (_section == null)
					_section = Forums.GetForum(CSContext.Current.SectionID);

				return _section;
			}
		}

		protected override bool IsFileValid(string filename, bool isRemote, int contentLengthBytes, ref string message)
		{
			if (!CSContext.Current.User.IsForumAdministrator)
			{
				ForumAttachmentSettings fas = ForumConfiguration.Instance().AttachmentSettings;
				if (fas.ValidateExtensions)
				{
					if (!fas.ValidationRegex.IsMatch(filename))
					{
						message = string.Format(ResourceManager.GetString("UploadAttachment_InvalidFileExtension"), fas.Extensions.Replace(";", ","));
						return false;
					}
				}

				if (!isRemote && fas.MaxAttachmentSize > 0 && contentLengthBytes / 1024 > fas.MaxAttachmentSize)
				{
					message = string.Format(ResourceManager.GetString("UploadAttachment_TooLarge"), fas.MaxAttachmentSize.ToString());
					return false;
				}
			}

			return true;
		}
	}
}

⌨️ 快捷键说明

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