Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Configuration / System / Configuration / FileUtil.cs / 1 / FileUtil.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.IO; using Microsoft.Win32; using System.Runtime.InteropServices; static internal class FileUtil { const int HRESULT_WIN32_FILE_NOT_FOUND = unchecked((int)0x80070002); const int HRESULT_WIN32_PATH_NOT_FOUND = unchecked((int)0x80070003); // // Use to avoid the perf hit of a Demand when the Demand is not necessary for security. // // If trueOnError is set, then return true if we cannot confirm that the file does NOT exist. // internal static bool FileExists(string filename, bool trueOnError) { UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data; bool ok = UnsafeNativeMethods.GetFileAttributesEx(filename, UnsafeNativeMethods.GetFileExInfoStandard, out data); if (ok) { // The path exists. Return true if it is a file, false if a directory. return (data.fileAttributes & (int) FileAttributes.Directory) != (int) FileAttributes.Directory; } else { if (!trueOnError) { return false; } else { // Return true if we cannot confirm that the file does NOT exist. int hr = Marshal.GetHRForLastWin32Error(); if (hr == HRESULT_WIN32_FILE_NOT_FOUND || hr == HRESULT_WIN32_PATH_NOT_FOUND) { return false; } else { return true; } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.IO; using Microsoft.Win32; using System.Runtime.InteropServices; static internal class FileUtil { const int HRESULT_WIN32_FILE_NOT_FOUND = unchecked((int)0x80070002); const int HRESULT_WIN32_PATH_NOT_FOUND = unchecked((int)0x80070003); // // Use to avoid the perf hit of a Demand when the Demand is not necessary for security. // // If trueOnError is set, then return true if we cannot confirm that the file does NOT exist. // internal static bool FileExists(string filename, bool trueOnError) { UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data; bool ok = UnsafeNativeMethods.GetFileAttributesEx(filename, UnsafeNativeMethods.GetFileExInfoStandard, out data); if (ok) { // The path exists. Return true if it is a file, false if a directory. return (data.fileAttributes & (int) FileAttributes.Directory) != (int) FileAttributes.Directory; } else { if (!trueOnError) { return false; } else { // Return true if we cannot confirm that the file does NOT exist. int hr = Marshal.GetHRForLastWin32Error(); if (hr == HRESULT_WIN32_FILE_NOT_FOUND || hr == HRESULT_WIN32_PATH_NOT_FOUND) { return false; } else { return true; } } } } } } // 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
- RequestTimeoutManager.cs
- AvTrace.cs
- WebPartTransformerCollection.cs
- XmlEntity.cs
- DecimalConstantAttribute.cs
- CatalogZone.cs
- BitmapEditor.cs
- TreeNodeClickEventArgs.cs
- StopStoryboard.cs
- IisNotInstalledException.cs
- _ChunkParse.cs
- DataKey.cs
- ConfigXmlCDataSection.cs
- SqlDataReaderSmi.cs
- StaticFileHandler.cs
- EmptyStringExpandableObjectConverter.cs
- MetaForeignKeyColumn.cs
- OrthographicCamera.cs
- AsyncCodeActivityContext.cs
- X509Utils.cs
- NumberSubstitution.cs
- IdentityManager.cs
- ProfilePropertyNameValidator.cs
- TextComposition.cs
- diagnosticsswitches.cs
- MetadataCacheItem.cs
- DesignerGenericWebPart.cs
- ExportFileRequest.cs
- SerializerDescriptor.cs
- Attributes.cs
- SemanticBasicElement.cs
- SvcMapFile.cs
- UIElementCollection.cs
- SerializerProvider.cs
- TreeNodeStyleCollection.cs
- CodePropertyReferenceExpression.cs
- ComboBoxAutomationPeer.cs
- ReaderWriterLock.cs
- SamlNameIdentifierClaimResource.cs
- EntityDataSourceView.cs
- serverconfig.cs
- WinFormsUtils.cs
- UserControlBuildProvider.cs
- RowSpanVector.cs
- HashHelper.cs
- StylusPlugInCollection.cs
- GrammarBuilderWildcard.cs
- FontUnitConverter.cs
- TextDocumentView.cs
- ListViewSortEventArgs.cs
- AttributeProviderAttribute.cs
- ConstraintManager.cs
- NestPullup.cs
- MimeMapping.cs
- NameValueCollection.cs
- CompatibleComparer.cs
- XmlAtomicValue.cs
- RefreshPropertiesAttribute.cs
- BoolExpression.cs
- Trace.cs
- DbTransaction.cs
- SQLDateTimeStorage.cs
- AuthenticationModulesSection.cs
- FormViewDeletedEventArgs.cs
- EventProxy.cs
- PublisherIdentityPermission.cs
- AnonymousIdentificationModule.cs
- TextDpi.cs
- TimeZoneInfo.cs
- RenameRuleObjectDialog.Designer.cs
- ListControl.cs
- TimeSpanConverter.cs
- VideoDrawing.cs
- TypeLibConverter.cs
- XmlSchemaComplexContent.cs
- XmlSchemas.cs
- MembershipValidatePasswordEventArgs.cs
- LineGeometry.cs
- BamlResourceDeserializer.cs
- Rotation3DAnimationUsingKeyFrames.cs
- InternalDuplexChannelListener.cs
- PropertyGroupDescription.cs
- DependencyObject.cs
- NumberSubstitution.cs
- PassportAuthentication.cs
- BuildManagerHost.cs
- DataContract.cs
- ExceptionUtil.cs
- NTAccount.cs
- TdsParserHelperClasses.cs
- SqlTriggerAttribute.cs
- SmiEventSink.cs
- ListBindingConverter.cs
- ConfigXmlReader.cs
- WebConfigManager.cs
- SqlBulkCopyColumnMappingCollection.cs
- PostBackOptions.cs
- ScrollItemProviderWrapper.cs
- ProviderUtil.cs
- WorkerRequest.cs