Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / FileUtil.cs / 1305376 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DesignTimeVisibleAttribute.cs
- Dictionary.cs
- Model3DGroup.cs
- WebRequest.cs
- PathFigure.cs
- Helpers.cs
- NameValuePair.cs
- DesignerImageAdapter.cs
- InputLanguageManager.cs
- HttpChannelHelpers.cs
- QilLiteral.cs
- CharEnumerator.cs
- KeyTime.cs
- OpacityConverter.cs
- BroadcastEventHelper.cs
- DataControlPagerLinkButton.cs
- ControlBuilder.cs
- Calendar.cs
- ProcessModuleCollection.cs
- CopyOfAction.cs
- x509store.cs
- NetTcpSecurity.cs
- LogWriteRestartAreaAsyncResult.cs
- IfAction.cs
- MsmqBindingElementBase.cs
- MultiViewDesigner.cs
- SafeFileMappingHandle.cs
- EventManager.cs
- SecurityRuntime.cs
- StateChangeEvent.cs
- FlowLayoutPanel.cs
- XmlNodeChangedEventManager.cs
- TextEditorSpelling.cs
- FocusTracker.cs
- RoutedEventHandlerInfo.cs
- ButtonField.cs
- IIS7WorkerRequest.cs
- ConfigXmlSignificantWhitespace.cs
- RegularExpressionValidator.cs
- DragDrop.cs
- RequestResizeEvent.cs
- CapiNative.cs
- ItemDragEvent.cs
- BatchStream.cs
- BitmapFrame.cs
- XmlSchemaComplexType.cs
- AspNetSynchronizationContext.cs
- ClientConfigurationHost.cs
- SQLByteStorage.cs
- ColumnBinding.cs
- DataControlPagerLinkButton.cs
- SignedInfo.cs
- PropertyMetadata.cs
- DataService.cs
- DbSourceParameterCollection.cs
- Token.cs
- CustomErrorsSectionWrapper.cs
- GeometryCombineModeValidation.cs
- PrimitiveCodeDomSerializer.cs
- DecimalConstantAttribute.cs
- MobileResource.cs
- ResourceIDHelper.cs
- SerializationTrace.cs
- CustomAttributeFormatException.cs
- UdpSocket.cs
- CheckableControlBaseAdapter.cs
- GroupQuery.cs
- ResponseStream.cs
- OracleCommand.cs
- CorrelationHandle.cs
- WebPartDescription.cs
- AssemblySettingAttributes.cs
- EntityDataSourceContainerNameItem.cs
- SqlCharStream.cs
- QilName.cs
- ResolveDuplex11AsyncResult.cs
- ConfigXmlElement.cs
- CatalogZone.cs
- StaticFileHandler.cs
- DataServiceHost.cs
- HandledMouseEvent.cs
- CodeAccessSecurityEngine.cs
- OneOfConst.cs
- validationstate.cs
- WebPartEditVerb.cs
- LogicalExpressionEditor.cs
- XamlReaderHelper.cs
- followingquery.cs
- OdbcConnectionOpen.cs
- TextRangeEditTables.cs
- StaticSiteMapProvider.cs
- PointConverter.cs
- StorageBasedPackageProperties.cs
- BaseProcessor.cs
- VisualTreeHelper.cs
- ListBoxAutomationPeer.cs
- SignalGate.cs
- OverloadGroupAttribute.cs
- ComboBox.cs
- SHA512.cs