Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / HtmlControls / HtmlInputFile.cs / 1 / HtmlInputFile.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HtmlInputFile.cs
*
* Copyright (c) 2000 Microsoft Corporation
*/
namespace System.Web.UI.HtmlControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
///
/// The class defines the
/// methods, properties, and events for the control. This class allows
/// programmatic access to the HTML <input type= file> element on the server.
/// It provides access to the stream, as well as a useful SaveAs functionality
/// provided by the
/// property.
///
///
/// This class only works if the
/// HtmlForm.Enctype property is set to "multipart/form-data".
/// Also, it does not maintain its
/// state across multiple round trips between browser and server. If the user sets
/// this value after a round trip, the value is lost.
///
///
[
ValidationProperty("Value")
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputFile : HtmlInputControl, IPostBackDataHandler {
/*
* Creates an intrinsic Html INPUT type=file control.
*/
///
/// Initializes a new instance of the class.
///
public HtmlInputFile() : base("file") {
}
/*
* Accept type property.
*/
///
///
/// Gets
/// or sets a comma-separated list of MIME encodings that
/// can be used to constrain the file types that the browser lets the user
/// select. For example, to restrict the
/// selection to images, the accept value image/* should be specified.
///
///
[
WebCategory("Behavior"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public string Accept {
get {
string s = Attributes["accept"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["accept"] = MapStringAttributeToString(value);
}
}
/*
* The property for the maximum characters allowed.
*/
///
///
/// Gets or sets the
/// maximum length of the file path of the file to upload
/// from the client machine.
///
///
[
WebCategory("Behavior"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int MaxLength {
get {
string s = Attributes["maxlength"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["maxlength"] = MapIntegerAttributeToString(value);
}
}
/*
* PostedFile property.
*/
///
/// Gets access to the uploaded file specified by a client.
///
[
WebCategory("Default"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public HttpPostedFile PostedFile {
get { return Context.Request.Files[RenderedNameAttribute];}
}
/*
* The property for the width in characters.
*/
///
/// Gets or sets the width of the file-path text box that the
/// browser displays when the
/// control is used on a page.
///
[
WebCategory("Appearance"),
DefaultValue(-1),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int Size {
get {
string s = Attributes["size"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["size"] = MapIntegerAttributeToString(value);
}
}
// ASURT 122262 : The value property isn't submitted back to us when the a page
// containing this control postsback, so required field validators are broken
// (value would contain the empty string). To fix this, we return the filename.
[
Browsable(false)
]
public override string Value {
get {
HttpPostedFile postedFile = PostedFile;
if (postedFile != null) {
return postedFile.FileName;
}
return String.Empty;
}
set {
// Throw here because setting the value on this tag has no effect on the
// rendering behavior and since we're always returning the posted file's
// filename, we don't want to get into a situation where the user
// sets a value and does not get back that value.
throw new NotSupportedException(SR.GetString(SR.Value_Set_Not_Supported, this.GetType().Name));
}
}
/*
* Method of IPostBackDataHandler interface to process posted data.
*/
///
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
return false;
}
/*
* Method of IPostBackDataHandler interface which is invoked whenever
* posted data for a control has changed. RadioButton fires an
* OnServerChange event.
*/
///
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
protected virtual void RaisePostDataChangedEvent() {
}
///
/// Raises the event. This method uses event arguments
/// to pass the event data to the control.
///
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
// ASURT 35328: use multipart encoding if no encoding is currently specified
HtmlForm form = Page.Form;
if (form != null && form.Enctype.Length == 0) {
form.Enctype = "multipart/form-data";
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HtmlInputFile.cs
*
* Copyright (c) 2000 Microsoft Corporation
*/
namespace System.Web.UI.HtmlControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
///
/// The class defines the
/// methods, properties, and events for the control. This class allows
/// programmatic access to the HTML <input type= file> element on the server.
/// It provides access to the stream, as well as a useful SaveAs functionality
/// provided by the
/// property.
///
///
/// This class only works if the
/// HtmlForm.Enctype property is set to "multipart/form-data".
/// Also, it does not maintain its
/// state across multiple round trips between browser and server. If the user sets
/// this value after a round trip, the value is lost.
///
///
[
ValidationProperty("Value")
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputFile : HtmlInputControl, IPostBackDataHandler {
/*
* Creates an intrinsic Html INPUT type=file control.
*/
///
/// Initializes a new instance of the class.
///
public HtmlInputFile() : base("file") {
}
/*
* Accept type property.
*/
///
///
/// Gets
/// or sets a comma-separated list of MIME encodings that
/// can be used to constrain the file types that the browser lets the user
/// select. For example, to restrict the
/// selection to images, the accept value image/* should be specified.
///
///
[
WebCategory("Behavior"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public string Accept {
get {
string s = Attributes["accept"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["accept"] = MapStringAttributeToString(value);
}
}
/*
* The property for the maximum characters allowed.
*/
///
///
/// Gets or sets the
/// maximum length of the file path of the file to upload
/// from the client machine.
///
///
[
WebCategory("Behavior"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int MaxLength {
get {
string s = Attributes["maxlength"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["maxlength"] = MapIntegerAttributeToString(value);
}
}
/*
* PostedFile property.
*/
///
/// Gets access to the uploaded file specified by a client.
///
[
WebCategory("Default"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public HttpPostedFile PostedFile {
get { return Context.Request.Files[RenderedNameAttribute];}
}
/*
* The property for the width in characters.
*/
///
/// Gets or sets the width of the file-path text box that the
/// browser displays when the
/// control is used on a page.
///
[
WebCategory("Appearance"),
DefaultValue(-1),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int Size {
get {
string s = Attributes["size"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["size"] = MapIntegerAttributeToString(value);
}
}
// ASURT 122262 : The value property isn't submitted back to us when the a page
// containing this control postsback, so required field validators are broken
// (value would contain the empty string). To fix this, we return the filename.
[
Browsable(false)
]
public override string Value {
get {
HttpPostedFile postedFile = PostedFile;
if (postedFile != null) {
return postedFile.FileName;
}
return String.Empty;
}
set {
// Throw here because setting the value on this tag has no effect on the
// rendering behavior and since we're always returning the posted file's
// filename, we don't want to get into a situation where the user
// sets a value and does not get back that value.
throw new NotSupportedException(SR.GetString(SR.Value_Set_Not_Supported, this.GetType().Name));
}
}
/*
* Method of IPostBackDataHandler interface to process posted data.
*/
///
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
return false;
}
/*
* Method of IPostBackDataHandler interface which is invoked whenever
* posted data for a control has changed. RadioButton fires an
* OnServerChange event.
*/
///
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
protected virtual void RaisePostDataChangedEvent() {
}
///
/// Raises the event. This method uses event arguments
/// to pass the event data to the control.
///
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
// ASURT 35328: use multipart encoding if no encoding is currently specified
HtmlForm form = Page.Form;
if (form != null && form.Enctype.Length == 0) {
form.Enctype = "multipart/form-data";
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ClockGroup.cs
- InheritablePropertyChangeInfo.cs
- UInt32Converter.cs
- RoleManagerEventArgs.cs
- DescriptionAttribute.cs
- commandenforcer.cs
- NotificationContext.cs
- ConstraintStruct.cs
- AnnotationComponentChooser.cs
- DocumentViewerBaseAutomationPeer.cs
- AssemblyGen.cs
- ProcessRequestArgs.cs
- DefaultWorkflowSchedulerService.cs
- StorageTypeMapping.cs
- DiscriminatorMap.cs
- TimeoutHelper.cs
- DesignerActionItem.cs
- SignatureResourcePool.cs
- IncrementalHitTester.cs
- CancelEventArgs.cs
- ListBoxChrome.cs
- ComponentEvent.cs
- DataObjectCopyingEventArgs.cs
- ListBoxItemAutomationPeer.cs
- Errors.cs
- Material.cs
- WindowsRichEditRange.cs
- DispatcherExceptionFilterEventArgs.cs
- XamlReaderHelper.cs
- SchemaCollectionCompiler.cs
- CookielessHelper.cs
- MembershipPasswordException.cs
- WorkflowView.cs
- DBSqlParser.cs
- DataSourceHelper.cs
- WebReferencesBuildProvider.cs
- FlatButtonAppearance.cs
- Int16Storage.cs
- Link.cs
- CLRBindingWorker.cs
- PrintControllerWithStatusDialog.cs
- ThrowOnMultipleAssignment.cs
- ListView.cs
- XmlHierarchicalDataSourceView.cs
- SystemFonts.cs
- DocumentPageTextView.cs
- EventMappingSettingsCollection.cs
- SoapCommonClasses.cs
- ReadContentAsBinaryHelper.cs
- Viewport2DVisual3D.cs
- PeerTransportListenAddressConverter.cs
- TraceLog.cs
- ServiceOperationParameter.cs
- Point4D.cs
- HtmlFormAdapter.cs
- SmiGettersStream.cs
- DefaultPropertyAttribute.cs
- UndoUnit.cs
- XmlNotation.cs
- PenThreadWorker.cs
- UTF7Encoding.cs
- MediaElement.cs
- XmlWellformedWriterHelpers.cs
- KeyFrames.cs
- InstanceCollisionException.cs
- XmlKeywords.cs
- CreationContext.cs
- Graph.cs
- LineBreak.cs
- IconHelper.cs
- BindingWorker.cs
- WebPartCancelEventArgs.cs
- SystemIPv4InterfaceProperties.cs
- SoapAttributeAttribute.cs
- DbFunctionCommandTree.cs
- PageAsyncTaskManager.cs
- UIHelper.cs
- DropDownButton.cs
- ServiceNameElement.cs
- DataSourceDescriptorCollection.cs
- GridLengthConverter.cs
- serverconfig.cs
- AsyncContentLoadedEventArgs.cs
- ProfileGroupSettingsCollection.cs
- UnsafeNativeMethods.cs
- DoubleSumAggregationOperator.cs
- ImageMetadata.cs
- ListViewPagedDataSource.cs
- XmlEventCache.cs
- DataGridRowEventArgs.cs
- EditingScopeUndoUnit.cs
- RotateTransform.cs
- ClientData.cs
- EntityClassGenerator.cs
- HandledMouseEvent.cs
- ConstraintManager.cs
- AmbientLight.cs
- X509ChainPolicy.cs
- SqlErrorCollection.cs
- XamlVector3DCollectionSerializer.cs