Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / FileUtil.cs / 1305376 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityFrameworkVersions.cs
- GotoExpression.cs
- RadioButtonDesigner.cs
- CodeDomConfigurationHandler.cs
- OleDbConnection.cs
- ParserOptions.cs
- PriorityItem.cs
- TableRowCollection.cs
- ACE.cs
- RowSpanVector.cs
- MetafileHeader.cs
- TextCompositionEventArgs.cs
- _NtlmClient.cs
- SQLConvert.cs
- MultilineStringConverter.cs
- TdsValueSetter.cs
- ActionMessageFilter.cs
- SelectionChangedEventArgs.cs
- Environment.cs
- OleDbTransaction.cs
- GenericAuthenticationEventArgs.cs
- ToolStripSystemRenderer.cs
- RenameRuleObjectDialog.cs
- GroupBoxAutomationPeer.cs
- AssemblyCollection.cs
- HtmlControlPersistable.cs
- ApplicationId.cs
- TextRenderer.cs
- VisualBasicSettingsConverter.cs
- KeyConverter.cs
- AuthenticateEventArgs.cs
- CollectionDataContractAttribute.cs
- Query.cs
- HttpCacheVaryByContentEncodings.cs
- ParsedAttributeCollection.cs
- ElasticEase.cs
- WindowsRichEdit.cs
- AccessText.cs
- PeerServiceMessageContracts.cs
- CodeThrowExceptionStatement.cs
- QilFactory.cs
- XNodeNavigator.cs
- TreeNodeBinding.cs
- FieldDescriptor.cs
- SqlDependencyListener.cs
- PropertyOverridesDialog.cs
- Clipboard.cs
- RelationshipEndCollection.cs
- BlockUIContainer.cs
- SafeNativeMethods.cs
- DialogBaseForm.cs
- TextFormatterContext.cs
- Point3DCollectionConverter.cs
- SimpleModelProvider.cs
- ComboBoxRenderer.cs
- ReachDocumentReferenceSerializer.cs
- ReceiveMessageRecord.cs
- TrackingProfile.cs
- SmtpAuthenticationManager.cs
- RegexCompiler.cs
- TimeSpan.cs
- CompilerCollection.cs
- TextDecorationCollectionConverter.cs
- InternalResources.cs
- StringAnimationUsingKeyFrames.cs
- PackageFilter.cs
- XmlEventCache.cs
- XmlParserContext.cs
- DependencyPropertyDescriptor.cs
- NameValuePermission.cs
- SctClaimDictionary.cs
- WizardForm.cs
- PixelShader.cs
- SqlEnums.cs
- ComponentCommands.cs
- ParserStreamGeometryContext.cs
- HMACSHA256.cs
- Executor.cs
- PingOptions.cs
- UTF7Encoding.cs
- GroupPartitionExpr.cs
- CoTaskMemHandle.cs
- FontFamilyValueSerializer.cs
- LayoutEditorPart.cs
- GlobalizationSection.cs
- localization.cs
- IntegrationExceptionEventArgs.cs
- CodeGenHelper.cs
- TcpTransportElement.cs
- EnlistmentState.cs
- SQLUtility.cs
- ObjectAssociationEndMapping.cs
- SqlConnectionHelper.cs
- typedescriptorpermission.cs
- BoolLiteral.cs
- GridViewDeleteEventArgs.cs
- IBuiltInEvidence.cs
- IdentityNotMappedException.cs
- DataControlFieldHeaderCell.cs
- CharEnumerator.cs