Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- invalidudtexception.cs
- HtmlImage.cs
- BamlLocalizabilityResolver.cs
- ValidatedControlConverter.cs
- ViewSimplifier.cs
- ExeContext.cs
- HttpPostedFile.cs
- SafeEventLogWriteHandle.cs
- SecurityTokenInclusionMode.cs
- IssuedTokenParametersElement.cs
- BidPrivateBase.cs
- CodeAccessSecurityEngine.cs
- Timer.cs
- Descriptor.cs
- _NegoStream.cs
- ListSortDescription.cs
- AutomationIdentifierGuids.cs
- MobileSysDescriptionAttribute.cs
- ConfigXmlDocument.cs
- MethodToken.cs
- EventSinkActivity.cs
- SoapSchemaMember.cs
- DbgUtil.cs
- DoubleAnimation.cs
- PerformanceCounterLib.cs
- QilBinary.cs
- EpmSyndicationContentDeSerializer.cs
- PopupRootAutomationPeer.cs
- AnimationLayer.cs
- MediaTimeline.cs
- StrongNameKeyPair.cs
- HtmlTableRowCollection.cs
- BindToObject.cs
- SolidBrush.cs
- PermissionSetEnumerator.cs
- JsonFormatWriterGenerator.cs
- XmlWriterSettings.cs
- SelectionProviderWrapper.cs
- XPathQilFactory.cs
- DataView.cs
- Bold.cs
- CustomErrorCollection.cs
- DataGridViewComponentPropertyGridSite.cs
- XmlCompatibilityReader.cs
- ComPlusTraceRecord.cs
- DropShadowEffect.cs
- XmlILIndex.cs
- DrawTreeNodeEventArgs.cs
- ServiceDeploymentInfo.cs
- FixedSOMSemanticBox.cs
- SizeFConverter.cs
- TextDecorations.cs
- Thumb.cs
- OutputCacheSection.cs
- Int64AnimationBase.cs
- TextChangedEventArgs.cs
- ObjectStateManager.cs
- VisualBasicSettingsConverter.cs
- CodeAttributeArgument.cs
- ValueSerializer.cs
- ToolBarButton.cs
- SQLUtility.cs
- Debugger.cs
- UIElementParaClient.cs
- OracleCommand.cs
- WebBrowserBase.cs
- DataGridViewRowPostPaintEventArgs.cs
- ComponentResourceManager.cs
- ConfigXmlWhitespace.cs
- SystemTcpConnection.cs
- ToolBarButtonClickEvent.cs
- ViewUtilities.cs
- ArrangedElementCollection.cs
- SafeWaitHandle.cs
- TreeNodeBinding.cs
- DialogResultConverter.cs
- XmlUtf8RawTextWriter.cs
- MimeWriter.cs
- FormViewPagerRow.cs
- WindowsIdentity.cs
- CodePageUtils.cs
- SystemNetHelpers.cs
- ScriptRef.cs
- AddInController.cs
- ContentWrapperAttribute.cs
- COAUTHINFO.cs
- DisableDpiAwarenessAttribute.cs
- FunctionNode.cs
- VisualTreeUtils.cs
- DrawingContextDrawingContextWalker.cs
- DataGridRelationshipRow.cs
- DesignerSerializationVisibilityAttribute.cs
- LinqDataSourceContextData.cs
- __TransparentProxy.cs
- KeyPressEvent.cs
- PersistencePipeline.cs
- AutomationIdentifier.cs
- TrackPoint.cs
- DurableRuntimeValidator.cs
- ProviderException.cs