Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- RootProfilePropertySettingsCollection.cs
- ColumnResizeUndoUnit.cs
- DataPagerFieldCommandEventArgs.cs
- CharAnimationBase.cs
- SendActivityValidator.cs
- SqlDataSourceConfigureSelectPanel.cs
- PropertyKey.cs
- XmlTypeMapping.cs
- GroupBox.cs
- SdlChannelSink.cs
- CursorConverter.cs
- ConfigurationLocation.cs
- AsyncOperationManager.cs
- SqlConnection.cs
- XmlQuerySequence.cs
- SerializationSectionGroup.cs
- RelativeSource.cs
- PixelShader.cs
- CompareValidator.cs
- OletxCommittableTransaction.cs
- MultiTrigger.cs
- MouseGesture.cs
- BitStack.cs
- ObsoleteAttribute.cs
- CharacterBuffer.cs
- SmtpReplyReader.cs
- WeakReference.cs
- CombinedGeometry.cs
- BindingListCollectionView.cs
- EncryptedType.cs
- NetworkAddressChange.cs
- NTAccount.cs
- TableRow.cs
- Int64Storage.cs
- HMACSHA384.cs
- PageFunction.cs
- DispatchWrapper.cs
- StreamGeometry.cs
- WindowsStatusBar.cs
- InheritanceAttribute.cs
- Int32EqualityComparer.cs
- ProtectedConfiguration.cs
- AutomationPropertyInfo.cs
- ConfigsHelper.cs
- BitSet.cs
- HScrollBar.cs
- contentDescriptor.cs
- SmtpCommands.cs
- CompareValidator.cs
- Switch.cs
- XPathArrayIterator.cs
- ToolStripDropDownButton.cs
- MexServiceChannelBuilder.cs
- MultiDataTrigger.cs
- LinkDesigner.cs
- SkinBuilder.cs
- InstalledFontCollection.cs
- SingleAnimation.cs
- ReferentialConstraint.cs
- DesignUtil.cs
- RawTextInputReport.cs
- PartDesigner.cs
- SortAction.cs
- CheckBoxRenderer.cs
- PersonalizationProvider.cs
- CodeIdentifier.cs
- DataError.cs
- InvalidOleVariantTypeException.cs
- ExtensionElement.cs
- PeerObject.cs
- EntityTypeEmitter.cs
- PersistenceTypeAttribute.cs
- EntityType.cs
- __Filters.cs
- MaskedTextBoxDesigner.cs
- Logging.cs
- ListBoxAutomationPeer.cs
- ObjRef.cs
- EventLogStatus.cs
- ToolStripItemRenderEventArgs.cs
- QueryReaderSettings.cs
- SqlTriggerContext.cs
- SchemaCreator.cs
- MdbDataFileEditor.cs
- DoubleLinkList.cs
- TaskScheduler.cs
- BamlVersionHeader.cs
- DocobjHost.cs
- XmlFormatExtensionPrefixAttribute.cs
- RequiredFieldValidator.cs
- X509ChainElement.cs
- SchemaImporterExtensionElementCollection.cs
- SQLBinaryStorage.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- TrackBar.cs
- CompiledQuery.cs
- VariantWrapper.cs
- TriggerBase.cs
- PopOutPanel.cs
- AmbientProperties.cs