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
- SqlProfileProvider.cs
- NumberSubstitution.cs
- TTSEngineTypes.cs
- ViewEventArgs.cs
- FunctionDetailsReader.cs
- SapiRecognizer.cs
- ToolStripLabel.cs
- Parsers.cs
- ScriptReferenceBase.cs
- UnsafeNativeMethods.cs
- ProtocolsSection.cs
- UpWmlPageAdapter.cs
- DbConnectionPoolCounters.cs
- ColumnClickEvent.cs
- TypeConverterHelper.cs
- SystemEvents.cs
- StyleSelector.cs
- PreparingEnlistment.cs
- NetworkAddressChange.cs
- DurableEnlistmentState.cs
- QueryStringParameter.cs
- RenderData.cs
- SelectedGridItemChangedEvent.cs
- DesignerAutoFormatStyle.cs
- XmlDataLoader.cs
- CheckBoxRenderer.cs
- DataKeyArray.cs
- AddingNewEventArgs.cs
- CodeCatchClause.cs
- GridViewRowEventArgs.cs
- DataTemplate.cs
- XmlIlVisitor.cs
- Trace.cs
- TreeNodeStyleCollection.cs
- BypassElementCollection.cs
- SplitterCancelEvent.cs
- DispatchProxy.cs
- OleDbError.cs
- SqlWebEventProvider.cs
- Memoizer.cs
- DocumentGrid.cs
- ScrollProperties.cs
- SafeNativeMethodsOther.cs
- Viewport2DVisual3D.cs
- DesignerActionUIStateChangeEventArgs.cs
- SessionState.cs
- FloaterParaClient.cs
- DockingAttribute.cs
- LogFlushAsyncResult.cs
- EntitySqlQueryCacheEntry.cs
- CryptoApi.cs
- HierarchicalDataBoundControlAdapter.cs
- DataGridTableCollection.cs
- ColorConvertedBitmap.cs
- PaintEvent.cs
- AnnotationMap.cs
- FileEnumerator.cs
- SqlDependencyListener.cs
- PersonalizationDictionary.cs
- PropertyConverter.cs
- EnumType.cs
- XmlSchemaCompilationSettings.cs
- _NegoState.cs
- PlatformCulture.cs
- TreeViewBindingsEditor.cs
- SplitterPanel.cs
- FormViewInsertEventArgs.cs
- SafePointer.cs
- MetadataItemEmitter.cs
- FixedDSBuilder.cs
- DoubleLink.cs
- ZipIOExtraFieldZip64Element.cs
- BypassElementCollection.cs
- DockPattern.cs
- LoadWorkflowByInstanceKeyCommand.cs
- XmlSchemaValidationException.cs
- ShapeTypeface.cs
- SurrogateSelector.cs
- TypeSemantics.cs
- ListViewSelectEventArgs.cs
- Byte.cs
- XmlSchemaInclude.cs
- DrawingImage.cs
- BamlCollectionHolder.cs
- TextServicesPropertyRanges.cs
- XamlTypeMapper.cs
- LocalServiceSecuritySettings.cs
- DataListComponentEditor.cs
- Int16AnimationBase.cs
- BufferedGraphicsManager.cs
- DockPattern.cs
- HwndSubclass.cs
- EntityContainerAssociationSet.cs
- StyleCollection.cs
- WebPartEditorOkVerb.cs
- TypeForwardedToAttribute.cs
- FileSystemWatcher.cs
- ThemeDirectoryCompiler.cs
- Pkcs9Attribute.cs
- Context.cs