📄 editdownload.cs
字号:
namespace ASPNET.StarterKit.Communities.Downloads {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// EditDowload Class
//
// Represents the Edit Download page. Enables users to edit files.
//
//*********************************************************************
public class EditDownload : ContentEditPage {
string _skinFileName = "Downloads_AddDownload.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Downloads.DownloadsSection";
HtmlInputFile txtDownloadFile;
TextBox txtDownloadTitle;
TextBox txtDownloadBriefDescription;
HtmlTextBox txtDownloadFullDescription;
TopicPicker dropTopics;
UploadValidator valUpload;
//*********************************************************************
//
// ContentPageID Property
//
// Stores the ID of the content being edited in View State
//
//*********************************************************************
int ContentPageID {
get {
return (int)ViewState["ContentPageID"];
}
set { ViewState["ContentPageID"] = value; }
}
//*********************************************************************
//
// SkinLoadDownload
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadDownload(Object s, SkinLoadEventArgs e) {
// Find the Form so that we can change the EncType of the post.
HtmlForm form = (HtmlForm)Page.FindControl("PageForm");
form.Enctype="multipart/form-data";
// Find Download Title
txtDownloadTitle = (TextBox)GetControl(e.Skin, "txtDownloadTitle" );
// Find Topics Panel and DropDownList
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
//Find Brief Description
txtDownloadBriefDescription = (TextBox)GetControl(e.Skin, "txtDownloadBriefDescription" );
//Find Full Description
txtDownloadFullDescription= (HtmlTextBox)GetControl(e.Skin, "txtDownloadFullDescription" );
// Find the download upload button
txtDownloadFile = (HtmlInputFile)GetControl(e.Skin, "txtDownloadFile");
// Get the Upload validator (and hide it)
valUpload = (UploadValidator)GetControl(e.Skin, "valUpload");
valUpload.Visible = false;
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
override protected void OnLoad(EventArgs e) {
if (!Page.IsPostBack) {
// Get the ContentPageID from QueryString
ContentPageID = Int32.Parse(Page.Request.QueryString["id"]);
// Get the download info
DownloadInfo _downloadInfo = (DownloadInfo)DownloadsUtility.GetDownloadInfo(objUserInfo.Username, ContentPageID);
EnsureChildControls();
// Assign value to topics
dropTopics.SelectedTopicID = _downloadInfo.TopicID;
// Assign other form values
txtDownloadTitle.Text = _downloadInfo.Title;
txtDownloadBriefDescription.Text = _downloadInfo.BriefDescription;
txtDownloadFullDescription.Text = _downloadInfo.FullDescription;
}
}
//*********************************************************************
//
// SubmitDownload Method
//
// This method is raised by clicking the Edit button in the Edit
// form. It adds the file to the database.
//
//*********************************************************************
private void SubmitDownload(Object s, EventArgs e) {
if (Page.IsValid) {
// Get Topic
int topicID = -1;
if (objSectionInfo.EnableTopics)
topicID = Int32.Parse(dropTopics.SelectedItem.Value);
// Get the file data
HttpPostedFile theFile = txtDownloadFile.PostedFile;
int fileSize = theFile.ContentLength;
byte[] fileBytes = new byte[fileSize];
System.IO.Stream myStream = theFile.InputStream;
myStream.Read(fileBytes,0,fileSize);
// Get file name
// The filename returns the entire client path.
// Filter for both Windows and Unix file paths.
Regex fileNameRE = new Regex("\\\\|/");
string[] fileNameSplit = fileNameRE.Split(theFile.FileName);
string _fileName = fileNameSplit[fileNameSplit.GetUpperBound(0)];
// Edit the file
DownloadsUtility.EditDownload
(
objUserInfo.Username,
objSectionInfo.ID,
ContentPageID,
txtDownloadTitle.Text,
txtDownloadBriefDescription.Text,
txtDownloadFullDescription.Text,
topicID,
_fileName,
fileBytes
);
// Redirect back to Download Page
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));
}
}
//*********************************************************************
//
// EditDownload Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public EditDownload() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify Section Content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadDownload);
this.Submit += new SubmitEventHandler(SubmitDownload);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -