Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / System / IO / FileFormatException.cs / 1 / FileFormatException.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: The FileFormatException class is thrown when an input file or a data stream that is supposed to conform
// to a certain file format specification is malformed.
//
// History:
// 10/21/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Windows;
using MS.Internal.WindowsBase;
namespace System.IO
{
///
/// The FileFormatException class is thrown when an input file or a data stream that is supposed to conform
/// to a certain file format specification is malformed.
///
[Serializable()]
public class FileFormatException : FormatException, ISerializable
{
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error,
/// such as "An input file or a data stream does not conform to the expected file format specification."
/// This message takes into account the current system culture.
///
public FileFormatException()
: base(SR.Get(SRID.FileFormatException))
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance with a specified error message.
///
/// The message that describes the error.
public FileFormatException(string message)
: base(message)
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance with a specified error message.
/// The InnerException property is initialized using the innerException parameter.
///
/// The error message that explains the reason for the exception.
/// The exception that is the cause of the current exception.
public FileFormatException(string message, Exception innerException)
: base(message, innerException)
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error and includes the file name,
/// such as "The file 'sourceUri' does not conform to the expected file format specification."
/// This message takes into account the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
///
/// The Uri of a file that caused this error.
public FileFormatException(Uri sourceUri)
: base(
sourceUri == null
? SR.Get(SRID.FileFormatException)
: SR.Get(SRID.FileFormatExceptionWithFileName, sourceUri))
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance using the message parameter.
/// The content of message is intended to be understood by humans.
/// The caller of this constructor is required to ensure that this string has been localized for the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
///
/// The Uri of a file that caused this error.
/// The message that describes the error.
public FileFormatException(Uri sourceUri, String message)
: base(message)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error and includes the file name,
/// such as "The file 'sourceUri' does not conform to the expected file format specification."
/// This message takes into account the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
/// The InnerException property is initialized using the innerException parameter.
///
/// The Uri of a file that caused this error.
/// The exception that is the cause of the current exception.
public FileFormatException(Uri sourceUri, Exception innerException)
: base(
sourceUri == null
? SR.Get(SRID.FileFormatException)
: SR.Get(SRID.FileFormatExceptionWithFileName, sourceUri),
innerException)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance using the message parameter.
/// The content of message is intended to be understood by humans.
/// The caller of this constructor is required to ensure that this string has been localized for the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
/// The InnerException property is initialized using the innerException parameter.
///
/// The Uri of a file that caused this error.
/// The message that describes the error.
/// The exception that is the cause of the current exception.
public FileFormatException(Uri sourceUri, String message, Exception innerException)
: base(message, innerException)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class and initializes it with serialized data.
/// This constructor is called during deserialization to reconstitute the exception object transmitted over a stream.
///
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
protected FileFormatException(SerializationInfo info, StreamingContext context) : base(info, context)
{
string sourceUriString = info.GetString("SourceUri");
if (sourceUriString != null)
_sourceUri = new Uri(sourceUriString, UriKind.RelativeOrAbsolute);
}
///
/// Sets the SerializationInfo object with the file name and additional exception information.
///
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
///
/// Critical: calls Exception.GetObjectData which LinkDemands
/// PublicOK: a demand exists here
///
[SecurityCritical]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
base.GetObjectData(info, context);
Uri sourceUri = SourceUri;
info.AddValue(
"SourceUri",
sourceUri == null
? null
: sourceUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped),
typeof(String)
);
}
///
/// Returns the name of a file that caused this exception. This property may be equal to an empty string
/// if obtaining the file path that caused the error was not possible.
///
/// The file name.
public Uri SourceUri
{
get
{
// Security: defense in depth, make sure the caller has path discovery permission for local file case.
if (_sourceUri != null && _sourceUri.IsAbsoluteUri && _sourceUri.IsFile)
SecurityHelper.DemandPathDiscovery(_sourceUri.LocalPath);
return _sourceUri;
}
}
private Uri _sourceUri;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: The FileFormatException class is thrown when an input file or a data stream that is supposed to conform
// to a certain file format specification is malformed.
//
// History:
// 10/21/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Windows;
using MS.Internal.WindowsBase;
namespace System.IO
{
///
/// The FileFormatException class is thrown when an input file or a data stream that is supposed to conform
/// to a certain file format specification is malformed.
///
[Serializable()]
public class FileFormatException : FormatException, ISerializable
{
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error,
/// such as "An input file or a data stream does not conform to the expected file format specification."
/// This message takes into account the current system culture.
///
public FileFormatException()
: base(SR.Get(SRID.FileFormatException))
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance with a specified error message.
///
/// The message that describes the error.
public FileFormatException(string message)
: base(message)
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance with a specified error message.
/// The InnerException property is initialized using the innerException parameter.
///
/// The error message that explains the reason for the exception.
/// The exception that is the cause of the current exception.
public FileFormatException(string message, Exception innerException)
: base(message, innerException)
{}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error and includes the file name,
/// such as "The file 'sourceUri' does not conform to the expected file format specification."
/// This message takes into account the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
///
/// The Uri of a file that caused this error.
public FileFormatException(Uri sourceUri)
: base(
sourceUri == null
? SR.Get(SRID.FileFormatException)
: SR.Get(SRID.FileFormatExceptionWithFileName, sourceUri))
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance using the message parameter.
/// The content of message is intended to be understood by humans.
/// The caller of this constructor is required to ensure that this string has been localized for the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
///
/// The Uri of a file that caused this error.
/// The message that describes the error.
public FileFormatException(Uri sourceUri, String message)
: base(message)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance to a system-supplied message that describes the error and includes the file name,
/// such as "The file 'sourceUri' does not conform to the expected file format specification."
/// This message takes into account the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
/// The InnerException property is initialized using the innerException parameter.
///
/// The Uri of a file that caused this error.
/// The exception that is the cause of the current exception.
public FileFormatException(Uri sourceUri, Exception innerException)
: base(
sourceUri == null
? SR.Get(SRID.FileFormatException)
: SR.Get(SRID.FileFormatExceptionWithFileName, sourceUri),
innerException)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class.
/// This constructor initializes the Message property of the new instance using the message parameter.
/// The content of message is intended to be understood by humans.
/// The caller of this constructor is required to ensure that this string has been localized for the current system culture.
/// The SourceUri property is initialized using the sourceUri parameter.
/// The InnerException property is initialized using the innerException parameter.
///
/// The Uri of a file that caused this error.
/// The message that describes the error.
/// The exception that is the cause of the current exception.
public FileFormatException(Uri sourceUri, String message, Exception innerException)
: base(message, innerException)
{
_sourceUri = sourceUri;
}
///
/// Creates a new instance of FileFormatException class and initializes it with serialized data.
/// This constructor is called during deserialization to reconstitute the exception object transmitted over a stream.
///
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
protected FileFormatException(SerializationInfo info, StreamingContext context) : base(info, context)
{
string sourceUriString = info.GetString("SourceUri");
if (sourceUriString != null)
_sourceUri = new Uri(sourceUriString, UriKind.RelativeOrAbsolute);
}
///
/// Sets the SerializationInfo object with the file name and additional exception information.
///
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
///
/// Critical: calls Exception.GetObjectData which LinkDemands
/// PublicOK: a demand exists here
///
[SecurityCritical]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
base.GetObjectData(info, context);
Uri sourceUri = SourceUri;
info.AddValue(
"SourceUri",
sourceUri == null
? null
: sourceUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped),
typeof(String)
);
}
///
/// Returns the name of a file that caused this exception. This property may be equal to an empty string
/// if obtaining the file path that caused the error was not possible.
///
/// The file name.
public Uri SourceUri
{
get
{
// Security: defense in depth, make sure the caller has path discovery permission for local file case.
if (_sourceUri != null && _sourceUri.IsAbsoluteUri && _sourceUri.IsFile)
SecurityHelper.DemandPathDiscovery(_sourceUri.LocalPath);
return _sourceUri;
}
}
private Uri _sourceUri;
}
}
// 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
- TextElementAutomationPeer.cs
- PixelShader.cs
- StrongNameMembershipCondition.cs
- AspCompat.cs
- WebPartEditorCancelVerb.cs
- CfgSemanticTag.cs
- TriggerBase.cs
- BaseAppDomainProtocolHandler.cs
- TemplateField.cs
- InputLanguageManager.cs
- ZipIOCentralDirectoryBlock.cs
- MenuItemCollection.cs
- ToolStripCollectionEditor.cs
- SystemInformation.cs
- TreeNode.cs
- ResourceIDHelper.cs
- SrgsDocumentParser.cs
- WebPartZoneBase.cs
- ElementAction.cs
- SystemNetworkInterface.cs
- AutomationTextAttribute.cs
- TimeSpanFormat.cs
- ResourceDescriptionAttribute.cs
- Model3DGroup.cs
- Suspend.cs
- SecureStringHasher.cs
- OleDbTransaction.cs
- SupportingTokenProviderSpecification.cs
- SqlRemoveConstantOrderBy.cs
- xdrvalidator.cs
- SoapDocumentServiceAttribute.cs
- TableLayoutColumnStyleCollection.cs
- WebPartDisplayMode.cs
- ScriptControlManager.cs
- SystemInformation.cs
- TokenizerHelper.cs
- ProvidePropertyAttribute.cs
- RequestCachePolicyConverter.cs
- InternalMappingException.cs
- XamlInt32CollectionSerializer.cs
- Action.cs
- HtmlTable.cs
- FrameSecurityDescriptor.cs
- WebChannelFactory.cs
- HWStack.cs
- FacetValues.cs
- SpellerInterop.cs
- SendMessageContent.cs
- Parameter.cs
- DataSvcMapFileSerializer.cs
- MeshGeometry3D.cs
- FontFamilyIdentifier.cs
- FormClosedEvent.cs
- Quaternion.cs
- WSFederationHttpBindingCollectionElement.cs
- RadioButton.cs
- SequenceRangeCollection.cs
- LocationSectionRecord.cs
- DbDataSourceEnumerator.cs
- DataGridViewCellConverter.cs
- ByteArrayHelperWithString.cs
- RawStylusInputCustomDataList.cs
- LeaseManager.cs
- LayoutEngine.cs
- GridViewDeletedEventArgs.cs
- ReceiveParametersContent.cs
- WebColorConverter.cs
- ReflectPropertyDescriptor.cs
- SR.cs
- AddInSegmentDirectoryNotFoundException.cs
- XmlSchemaChoice.cs
- _Connection.cs
- SqlDataSourceFilteringEventArgs.cs
- TableMethodGenerator.cs
- XmlNodeList.cs
- RemotingAttributes.cs
- ArcSegment.cs
- KnownTypesProvider.cs
- TouchesCapturedWithinProperty.cs
- ByteAnimation.cs
- BitmapMetadata.cs
- BitStream.cs
- TargetFrameworkUtil.cs
- DataGridViewRowsAddedEventArgs.cs
- PropertyConverter.cs
- PageParser.cs
- ObjectDataSourceStatusEventArgs.cs
- ProfileServiceManager.cs
- SelectionEditingBehavior.cs
- RoutedEvent.cs
- InkCanvasSelectionAdorner.cs
- DataGridCellsPresenter.cs
- UntypedNullExpression.cs
- PropVariant.cs
- AccessDataSource.cs
- JavaScriptString.cs
- DoubleCollectionValueSerializer.cs
- SqlDataSource.cs
- XmlSchemaAnnotation.cs
- DelegateBodyWriter.cs