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
- PageTheme.cs
- AdRotatorDesigner.cs
- Point3DKeyFrameCollection.cs
- COM2TypeInfoProcessor.cs
- _Semaphore.cs
- Preprocessor.cs
- RegexBoyerMoore.cs
- SqlDataReader.cs
- QilNode.cs
- TextSelectionProcessor.cs
- MultiSelectRootGridEntry.cs
- TableChangeProcessor.cs
- EditingContext.cs
- ContainerSelectorGlyph.cs
- Memoizer.cs
- DataGridViewRowCollection.cs
- XhtmlStyleClass.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- StateMachine.cs
- TextShapeableCharacters.cs
- LicenseProviderAttribute.cs
- DataViewListener.cs
- ScrollableControlDesigner.cs
- ADConnectionHelper.cs
- DrawingImage.cs
- IISUnsafeMethods.cs
- GuidelineSet.cs
- UniqueIdentifierService.cs
- HttpModulesSection.cs
- XmlIterators.cs
- AssociatedControlConverter.cs
- DataServiceRequestOfT.cs
- StateChangeEvent.cs
- SoapIgnoreAttribute.cs
- ProcessModuleCollection.cs
- StatusStrip.cs
- RenderTargetBitmap.cs
- DynamicContractTypeBuilder.cs
- NamespaceMapping.cs
- SchemaImporter.cs
- SqlInfoMessageEvent.cs
- WinEventTracker.cs
- DiagnosticsConfiguration.cs
- BaseEntityWrapper.cs
- CDSCollectionETWBCLProvider.cs
- RelOps.cs
- VisualTarget.cs
- SapiRecognizer.cs
- FormViewPagerRow.cs
- FtpWebRequest.cs
- InvalidDataException.cs
- Substitution.cs
- UnsafeNativeMethods.cs
- DataGridCellInfo.cs
- DateTimeOffset.cs
- XPathChildIterator.cs
- sapiproxy.cs
- SplineQuaternionKeyFrame.cs
- ToolStripMenuItem.cs
- EntityUtil.cs
- XmlBufferReader.cs
- ConversionHelper.cs
- BindingCompleteEventArgs.cs
- HyperLinkDesigner.cs
- HiddenFieldPageStatePersister.cs
- ClientSettingsStore.cs
- TextBoxDesigner.cs
- OdbcInfoMessageEvent.cs
- UnsafeMethods.cs
- BuildProviderAppliesToAttribute.cs
- WebServiceData.cs
- DbConnectionOptions.cs
- PropertyGroupDescription.cs
- NotifyIcon.cs
- WaitHandle.cs
- DecoderNLS.cs
- ProfileSettings.cs
- ObjectManager.cs
- ConfigXmlElement.cs
- MatrixTransform3D.cs
- JpegBitmapEncoder.cs
- Content.cs
- TripleDESCryptoServiceProvider.cs
- MetaForeignKeyColumn.cs
- RawUIStateInputReport.cs
- TypeConstant.cs
- SimpleBitVector32.cs
- AccessKeyManager.cs
- WindowPatternIdentifiers.cs
- WindowsProgressbar.cs
- RecognizedWordUnit.cs
- UserControl.cs
- DefinitionUpdate.cs
- WorkflowView.cs
- DataTableReaderListener.cs
- UserInitiatedNavigationPermission.cs
- SmiXetterAccessMap.cs
- UserPersonalizationStateInfo.cs
- Point4DConverter.cs
- XmlSchemaSimpleContent.cs