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
- ClientSession.cs
- DoubleAnimation.cs
- Timer.cs
- PaperSource.cs
- QilReplaceVisitor.cs
- WindowsFont.cs
- ClientFormsIdentity.cs
- TextRangeEdit.cs
- CursorConverter.cs
- StdRegProviderWrapper.cs
- SqlLiftWhereClauses.cs
- Dispatcher.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- ObsoleteAttribute.cs
- ToolStripItemImageRenderEventArgs.cs
- TextTreeRootNode.cs
- ZoneLinkButton.cs
- ConfigurationStrings.cs
- OdbcUtils.cs
- RemoveStoryboard.cs
- ToolStripDropTargetManager.cs
- FileUpload.cs
- Crc32Helper.cs
- KeyboardDevice.cs
- BaseHashHelper.cs
- BoolExpression.cs
- WebPartCloseVerb.cs
- SoundPlayer.cs
- Journaling.cs
- EntitySetRetriever.cs
- PropertyPathWorker.cs
- Decoder.cs
- DataPagerField.cs
- UnsafeNetInfoNativeMethods.cs
- X509CertificateInitiatorServiceCredential.cs
- SqlColumnizer.cs
- GacUtil.cs
- ExpanderAutomationPeer.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- ToolBarDesigner.cs
- DBSchemaTable.cs
- WindowVisualStateTracker.cs
- DataGridView.cs
- Accessible.cs
- CodeThrowExceptionStatement.cs
- RowToFieldTransformer.cs
- Process.cs
- PointLight.cs
- CollectionViewSource.cs
- XamlDebuggerXmlReader.cs
- MetadataArtifactLoaderFile.cs
- RTLAwareMessageBox.cs
- control.ime.cs
- TrackingCondition.cs
- TextBoxBase.cs
- SecondaryIndexDefinition.cs
- DataListItemEventArgs.cs
- RegexParser.cs
- NetworkInformationException.cs
- DataContext.cs
- CharacterMetrics.cs
- FixedSOMGroup.cs
- QilParameter.cs
- TaiwanLunisolarCalendar.cs
- httpapplicationstate.cs
- ConnectivityStatus.cs
- Command.cs
- TrackingProfile.cs
- SecurityStandardsManager.cs
- LookupNode.cs
- WizardForm.cs
- TextChange.cs
- TrackingProvider.cs
- ProcessHostConfigUtils.cs
- EqualityComparer.cs
- PerformanceCounterLib.cs
- ListView.cs
- DataBoundLiteralControl.cs
- SimpleType.cs
- DocumentViewerBase.cs
- EventLog.cs
- PkcsMisc.cs
- Int32Animation.cs
- MenuAdapter.cs
- TableRow.cs
- FormClosingEvent.cs
- MarkupCompiler.cs
- HtmlInputText.cs
- TreeViewDesigner.cs
- MessageLoggingFilterTraceRecord.cs
- VerificationException.cs
- IpcChannel.cs
- MD5.cs
- EntityDataSourceSelectedEventArgs.cs
- HttpSocketManager.cs
- WriteTimeStream.cs
- SystemException.cs
- TdsParserStateObject.cs
- HistoryEventArgs.cs
- RecordBuilder.cs