Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- CellConstant.cs
- Win32KeyboardDevice.cs
- QilXmlReader.cs
- WebPartDeleteVerb.cs
- GraphicsState.cs
- ISAPIApplicationHost.cs
- ExpandSegmentCollection.cs
- FunctionUpdateCommand.cs
- AdornerPresentationContext.cs
- XmlReader.cs
- X509Utils.cs
- BlurEffect.cs
- SizeLimitedCache.cs
- XPathSingletonIterator.cs
- Imaging.cs
- ObjectListField.cs
- CmsUtils.cs
- WorkflowRequestContext.cs
- SchemaTypeEmitter.cs
- Activity.cs
- QilChoice.cs
- XmlAttributeProperties.cs
- TextBlock.cs
- TypeSystem.cs
- AssemblyLoader.cs
- IdnMapping.cs
- HwndSourceKeyboardInputSite.cs
- ListViewTableCell.cs
- XsltConvert.cs
- DesignerForm.cs
- DebugView.cs
- SessionStateContainer.cs
- XmlSchemaSimpleType.cs
- FileDialog_Vista_Interop.cs
- WebPartVerbsEventArgs.cs
- PtsCache.cs
- BitmapEffectInputConnector.cs
- SecurityException.cs
- GlobalProxySelection.cs
- WebPartManagerInternals.cs
- DataErrorValidationRule.cs
- ColumnWidthChangingEvent.cs
- WorkflowTransactionOptions.cs
- ObfuscateAssemblyAttribute.cs
- DropAnimation.xaml.cs
- WebPartConnectionsConnectVerb.cs
- PerformanceCounters.cs
- SHA1Managed.cs
- BasicCellRelation.cs
- MultipartContentParser.cs
- ConfigurationPropertyCollection.cs
- EntitySqlQueryBuilder.cs
- DataListItem.cs
- IsolatedStorageFile.cs
- DelegatingMessage.cs
- XsltQilFactory.cs
- QilCloneVisitor.cs
- RightsManagementInformation.cs
- securitycriticaldataformultiplegetandset.cs
- CalendarDay.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- CreateUserErrorEventArgs.cs
- ModelVisual3D.cs
- CopyOnWriteList.cs
- CurrencyWrapper.cs
- Binding.cs
- InternalPolicyElement.cs
- GeometryHitTestParameters.cs
- MultiView.cs
- MediaContext.cs
- ApplicationFileParser.cs
- ListViewCancelEventArgs.cs
- OpCellTreeNode.cs
- SystemInfo.cs
- TreeWalker.cs
- PeerChannelListener.cs
- SqlDataRecord.cs
- EdgeProfileValidation.cs
- ToolStripMenuItemDesigner.cs
- CodeVariableDeclarationStatement.cs
- HttpDateParse.cs
- MethodResolver.cs
- ErrorFormatterPage.cs
- streamingZipPartStream.cs
- NonParentingControl.cs
- UserControl.cs
- PackagingUtilities.cs
- Style.cs
- SqlClientFactory.cs
- ServiceMetadataBehavior.cs
- ScriptMethodAttribute.cs
- Instrumentation.cs
- GroupQuery.cs
- OdbcEnvironment.cs
- HttpHandlerActionCollection.cs
- KnownTypesHelper.cs
- Debug.cs
- XmlCustomFormatter.cs
- WebPartUserCapability.cs
- SqlDataSourceFilteringEventArgs.cs