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
- TriggerAction.cs
- NumberFunctions.cs
- WindowsSecurityToken.cs
- ConfigurationConverterBase.cs
- StaticResourceExtension.cs
- Hyperlink.cs
- HMACMD5.cs
- CapabilitiesUse.cs
- XmlSchemaAnyAttribute.cs
- SecurityHeaderTokenResolver.cs
- WriteFileContext.cs
- StreamGeometry.cs
- ScriptingJsonSerializationSection.cs
- ItemCollection.cs
- SrgsElementFactory.cs
- WebConfigurationHost.cs
- ReflectionHelper.cs
- activationcontext.cs
- OptimizedTemplateContent.cs
- LayoutTableCell.cs
- NativeMethods.cs
- PersianCalendar.cs
- VisualTreeUtils.cs
- XmlCodeExporter.cs
- ManipulationStartedEventArgs.cs
- SimpleRecyclingCache.cs
- IdnElement.cs
- LongTypeConverter.cs
- NotFiniteNumberException.cs
- ClientData.cs
- WebPartCatalogAddVerb.cs
- DBConnectionString.cs
- ExpressionDumper.cs
- DispatcherHooks.cs
- ActivitySurrogate.cs
- BufferedWebEventProvider.cs
- WebPartEventArgs.cs
- Margins.cs
- MetadataSource.cs
- EntitySetDataBindingList.cs
- ContractDescription.cs
- AbstractExpressions.cs
- CacheHelper.cs
- ConfigXmlReader.cs
- ConstNode.cs
- XmlBinaryWriter.cs
- RoutedCommand.cs
- UrlMappingsSection.cs
- DragAssistanceManager.cs
- CollectionEditVerbManager.cs
- PeerNearMe.cs
- ExceptQueryOperator.cs
- BrowserCapabilitiesFactoryBase.cs
- NameSpaceEvent.cs
- PrinterResolution.cs
- WhitespaceRule.cs
- DataError.cs
- MethodAccessException.cs
- StringKeyFrameCollection.cs
- Trace.cs
- HandlerFactoryCache.cs
- Color.cs
- PrintingPermission.cs
- FixedSOMTable.cs
- JapaneseCalendar.cs
- AssemblyCollection.cs
- WasEndpointConfigContainer.cs
- CustomValidator.cs
- CodeIdentifiers.cs
- Imaging.cs
- EvidenceTypeDescriptor.cs
- InvokeProviderWrapper.cs
- FixedTextSelectionProcessor.cs
- ContextQuery.cs
- ToolBarButtonClickEvent.cs
- basecomparevalidator.cs
- SizeChangedEventArgs.cs
- RepeaterItemEventArgs.cs
- RoutedEvent.cs
- HtmlShimManager.cs
- MappingException.cs
- X509Chain.cs
- BitArray.cs
- Form.cs
- ValueType.cs
- LambdaExpression.cs
- ResourcePermissionBaseEntry.cs
- BamlTreeMap.cs
- ListViewUpdatedEventArgs.cs
- ParameterCollection.cs
- ProfileParameter.cs
- safex509handles.cs
- VectorConverter.cs
- MessageSmuggler.cs
- SeverityFilter.cs
- AnnotationAdorner.cs
- WindowsRebar.cs
- XmlSchemaObjectTable.cs
- Empty.cs
- _ConnectOverlappedAsyncResult.cs