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
- PhysicalAddress.cs
- HttpCookiesSection.cs
- ContentAlignmentEditor.cs
- CreateUserWizardStep.cs
- ExtenderControl.cs
- WorkflowViewManager.cs
- EventLogEntry.cs
- SmtpMail.cs
- AccessedThroughPropertyAttribute.cs
- RegularExpressionValidator.cs
- XPathNavigatorKeyComparer.cs
- HtmlTableRow.cs
- IdentityManager.cs
- SmtpSection.cs
- TypedCompletedAsyncResult.cs
- Column.cs
- IsolatedStorageSecurityState.cs
- TextParaLineResult.cs
- UnsafeNativeMethods.cs
- LinkAreaEditor.cs
- SecurityPermission.cs
- TextRunTypographyProperties.cs
- StatementContext.cs
- RoleGroupCollection.cs
- WindowsListView.cs
- DataQuery.cs
- CompModSwitches.cs
- TogglePatternIdentifiers.cs
- ApplicationInfo.cs
- RowBinding.cs
- StreamInfo.cs
- Stream.cs
- smtppermission.cs
- DocumentPageViewAutomationPeer.cs
- figurelength.cs
- ExtendedProtectionPolicyTypeConverter.cs
- IgnorePropertiesAttribute.cs
- SpotLight.cs
- SafeNativeMethods.cs
- ClientRuntimeConfig.cs
- CodeEventReferenceExpression.cs
- Scheduling.cs
- XmlSchemaAny.cs
- PassportAuthentication.cs
- UrlAuthFailedErrorFormatter.cs
- XmlDigitalSignatureProcessor.cs
- Literal.cs
- OutputCacheProviderCollection.cs
- XPathMessageFilterTable.cs
- ResourcePermissionBaseEntry.cs
- ToolStripHighContrastRenderer.cs
- TreeNodeStyle.cs
- SchemaNotation.cs
- DependencyPropertyConverter.cs
- ObjectKeyFrameCollection.cs
- ExtenderProvidedPropertyAttribute.cs
- SiteMapDataSourceDesigner.cs
- TrackBarDesigner.cs
- ProgressPage.cs
- ToolStripTextBox.cs
- entityreference_tresulttype.cs
- HelpEvent.cs
- XpsFixedDocumentReaderWriter.cs
- EllipseGeometry.cs
- ExtenderProvidedPropertyAttribute.cs
- TextSegment.cs
- RawKeyboardInputReport.cs
- DataGridViewToolTip.cs
- NativeMethods.cs
- InternalDispatchObject.cs
- Select.cs
- PropertyItemInternal.cs
- OutputBuffer.cs
- WebControlAdapter.cs
- SQLDecimal.cs
- Variable.cs
- CodeExporter.cs
- GroupBox.cs
- BitmapImage.cs
- FillRuleValidation.cs
- PrintPreviewControl.cs
- SectionInformation.cs
- Drawing.cs
- HelpKeywordAttribute.cs
- Domain.cs
- UnsafeNativeMethods.cs
- GraphicsPathIterator.cs
- EntityDataSourceValidationException.cs
- XmlAtomicValue.cs
- RegistrySecurity.cs
- PathGradientBrush.cs
- EdmEntityTypeAttribute.cs
- PersonalizationStateQuery.cs
- TableAutomationPeer.cs
- XmlCDATASection.cs
- DbConnectionHelper.cs
- Metafile.cs
- NonParentingControl.cs
- FileUpload.cs
- CodeConstructor.cs