C# FileNotFoundException.ToString的代码示例

FileNotFoundException.ToString方法的主要功能描述

通过代码示例来学习C# FileNotFoundException.ToString方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


FileNotFoundException.ToString是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的FileNotFoundException.ToString() 已经帮大家高亮显示了,大家可以重点学习FileNotFoundException.ToString() 方法的写法,从而快速掌握该方法的应用。

FileNotFoundException.ToString的代码示例1 - TryDeleteStatusCacheFile()

    using System.IO;

        private bool TryDeleteStatusCacheFile()
        {
            Debug.Assert(Monitor.IsEntered(this.cacheFileLock), "Attempting to delete the git status cache file without the cacheFileLock");

            try
            {
                if (this.context.FileSystem.FileExists(this.serializedGitStatusFilePath))
                {
                    this.context.FileSystem.DeleteFile(this.serializedGitStatusFilePath);
                }
            }
            catch (IOException ex) when (ex is FileNotFoundException || ex is DirectoryNotFoundException)
            {
                // Unexpected, but maybe something deleted the file out from underneath us...
                // As the file is deleted, lets continue with the status generation..
            }
            catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException)
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Area", EtwArea);
                metadata.Add("Exception", ex.ToString());

                this.context.Tracer.RelatedWarning(
                    metadata,
                    string.Format("GitStatusCache encountered exception attempting to delete cache file at {0}.", this.serializedGitStatusFilePath),
                    Keywords.Telemetry);

                return false;
            }

            return true;
        }
    

开发者ID: microsoft,   项目名称: VFSForGit,   代码行数: 34,   代码来源: GitStatusCache.cs

在microsoft提供的TryDeleteStatusCacheFile()方法中,该源代码示例一共有34行, 其中使用了FileNotFoundException.ToString()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString的代码示例2 - TryCopyNativeLibIfDriverVersionsMatch()

    using System.IO;

        public static bool TryCopyNativeLibIfDriverVersionsMatch(ITracer tracer, PhysicalFileSystem fileSystem, out string copyNativeDllError)
        {
            string system32NativeLibraryPath = Path.Combine(Environment.SystemDirectory, ProjFSNativeLibFileName);
            if (fileSystem.FileExists(system32NativeLibraryPath))
            {
                copyNativeDllError = $"{ProjFSNativeLibFileName} already exists at {system32NativeLibraryPath}";
                return false;
            }

            string gvfsProcessLocation = ProcessHelper.GetCurrentProcessLocation();
            string nonInboxNativeLibInstallPath;
            string packagedNativeLibPath;
            GetNativeLibPaths(gvfsProcessLocation, out packagedNativeLibPath, out nonInboxNativeLibInstallPath);
            if (fileSystem.FileExists(nonInboxNativeLibInstallPath))
            {
                copyNativeDllError = $"{ProjFSNativeLibFileName} already exists at {nonInboxNativeLibInstallPath}";
                return false;
            }

            if (!fileSystem.FileExists(packagedNativeLibPath))
            {
                copyNativeDllError = $"{packagedNativeLibPath} not found, no {ProjFSNativeLibFileName} available to copy";
                return false;
            }

            string packagedPrjfltDriverPath = Path.Combine(gvfsProcessLocation, "Filter", DriverFileName);
            if (!fileSystem.FileExists(packagedPrjfltDriverPath))
            {
                copyNativeDllError = $"{packagedPrjfltDriverPath} not found, unable to validate that packaged driver matches installed driver";
                return false;
            }

            string system32PrjfltDriverPath = Path.Combine(Environment.ExpandEnvironmentVariables(System32DriversRoot), DriverFileName);
            if (!fileSystem.FileExists(system32PrjfltDriverPath))
            {
                copyNativeDllError = $"{system32PrjfltDriverPath} not found, unable to validate that packaged driver matches installed driver";
                return false;
            }

            FileVersionInfo packagedDriverVersion;
            FileVersionInfo system32DriverVersion;
            try
            {
                packagedDriverVersion = fileSystem.GetVersionInfo(packagedPrjfltDriverPath);
                system32DriverVersion = fileSystem.GetVersionInfo(system32PrjfltDriverPath);
                if (!fileSystem.FileVersionsMatch(packagedDriverVersion, system32DriverVersion))
                {
                    copyNativeDllError = $"Packaged sys FileVersion '{packagedDriverVersion.FileVersion}' does not match System32 sys FileVersion '{system32DriverVersion.FileVersion}'";
                    return false;
                }

                if (!fileSystem.ProductVersionsMatch(packagedDriverVersion, system32DriverVersion))
                {
                    copyNativeDllError = $"Packaged sys ProductVersion '{packagedDriverVersion.ProductVersion}' does not match System32 sys ProductVersion '{system32DriverVersion.ProductVersion}'";
                    return false;
                }
            }
            catch (FileNotFoundException e)
            {
                EventMetadata metadata = CreateEventMetadata(e);
                tracer.RelatedWarning(
                    metadata,
                    $"{nameof(TryCopyNativeLibIfDriverVersionsMatch)}: Exception caught while comparing sys versions");
                copyNativeDllError = $"Exception caught while comparing sys versions: {e.Message}";
                return false;
            }

            EventMetadata driverVersionMetadata = CreateEventMetadata();
            driverVersionMetadata.Add($"{nameof(packagedDriverVersion)}.FileVersion", packagedDriverVersion.FileVersion.ToString());
            driverVersionMetadata.Add($"{nameof(system32DriverVersion)}.FileVersion", system32DriverVersion.FileVersion.ToString());
            driverVersionMetadata.Add($"{nameof(packagedDriverVersion)}.ProductVersion", packagedDriverVersion.ProductVersion.ToString());
            driverVersionMetadata.Add($"{nameof(system32DriverVersion)}.ProductVersion", system32DriverVersion.ProductVersion.ToString());
            tracer.RelatedInfo(driverVersionMetadata, $"{nameof(TryCopyNativeLibIfDriverVersionsMatch)}: Copying native library");

            if (!TryCopyNativeLibToNonInboxInstallLocation(tracer, fileSystem, gvfsProcessLocation))
            {
                copyNativeDllError = "Failed to copy native library";
                return false;
            }

            copyNativeDllError = null;
            return true;
        }
    

开发者ID: microsoft,   项目名称: VFSForGit,   代码行数: 85,   代码来源: ProjFSFilter.cs

在microsoft提供的TryCopyNativeLibIfDriverVersionsMatch()方法中,该源代码示例一共有85行, 其中使用了FileNotFoundException.ToString()4次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString的代码示例3 - Upload()

    using System.IO;

        private void Upload()
        {
            if (string.IsNullOrEmpty(_settings.ApiKey))
            {
                MessageBox.Show(LocalizationHelper.Base.UploadForm_NoApiKey, LocalizationHelper.Base.UploadForm_InvalidKey, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (_settings.ApiKey.Length != 64)
            {
                MessageBox.Show(LocalizationHelper.Base.UploadForm_InvalidLength, LocalizationHelper.Base.UploadForm_InvalidKey, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            
            ChangeStatus(LocalizationHelper.Base.Message_Init);
            _client = new RestClient("https://www.virustotal.com");

            if (!File.Exists(_fileName))
            {
                throw new FileNotFoundException();
            }

            ChangeStatus(LocalizationHelper.Base.Message_Check);
            var reportRequest = new RestRequest("vtapi/v2/file/report", Method.Post);
            reportRequest.AddParameter("apikey", _settings.ApiKey);
            reportRequest.AddParameter("resource", Utils.GetMD5(_fileName));

            var reportResponse = _client.Execute(reportRequest);
            var reportContent = reportResponse.Content;
            dynamic reportJson = JsonConvert.DeserializeObject(reportContent);

            try
            {
                var reportLink = reportJson.permalink.ToString();
                Process.Start(reportLink);

                if (_settings.DirectUpload) CloseWindow();
            }
            catch (RuntimeBinderException)
            {
                // Json does not contain permalink which means it's a new file (or the request failed)
                ChangeStatus(LocalizationHelper.Base.Message_Upload);
                var scanRequest = new RestRequest("vtapi/v2/file/scan", Method.Post);
                scanRequest.AddParameter("apikey", _settings.ApiKey);
                scanRequest.AddFile("file", _fileName);

                var scanResponse = _client.Execute(scanRequest);
                var scanContent = scanResponse.Content;
                // TODO: check for HTML (file too large)
                dynamic scanJson = JsonConvert.DeserializeObject(scanContent);

                try
                {
                    string scanLink = scanJson.permalink.ToString();

                    // An example link can look like this:
                    // https://www.virustotal.com/gui/file//detection/
                    // If we don't remove the the scanid, then it will fail on new files since the scan did not finish
                    // Removing it like this will show the analysis progress for new files
                    scanLink = scanLink.Remove(scanLink.IndexOf("/detection"));
                    
                    Process.Start(scanLink);

                    if (_settings.DirectUpload) CloseWindow();
                }
                catch (Exception)
                {
                    // Response does not contain permalink so it failed
                    ChangeStatus(LocalizationHelper.Base.Message_NoLink);
                    Finish(false);
                    return;
                }
            }

            Finish(true);
        }
    

开发者ID: SamuelTulach,   项目名称: VirusTotalUploader,   代码行数: 78,   代码来源: UploadForm.cs

在SamuelTulach提供的Upload()方法中,该源代码示例一共有78行, 其中使用了FileNotFoundException.ToString()2次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString的代码示例4 - LoadPlugins()

    using System.IO;
        public static ICollection LoadPlugins()
        {
            string path = Runtime.ExecutableDir + "/Lib/Plugins";

            string[] dllFileNames = null;
            if (Directory.Exists(path))
            {
                dllFileNames = Directory.GetFiles(path, "*.Plg.dll");
            }
            if (dllFileNames == null)
            {
                System.Windows.Forms.MessageBox.Show($"Could not find any plugins in {path}", "",
                    System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return new List();
            }

            ICollection assemblies = new List(dllFileNames.Length);
            foreach (string dllFile in dllFileNames)
            {
                AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
                Assembly assembly = Assembly.Load(an);
                assemblies.Add(assembly);
            }

            Type pluginType = typeof(IPlugin);
            ICollection pluginTypes = new List();
            foreach (Assembly assembly in assemblies)
            {
                if (assembly != null)
                {
                    try
                    {
                        Type[] types = assembly.GetTypes();
                        foreach (Type type in types)
                        {
                            if (type.IsInterface || type.IsAbstract)
                            {
                                continue;
                            }
                            else
                            {
                                if (type.GetInterface(pluginType.FullName) != null)
                                {
                                    pluginTypes.Add(type);
                                }
                            }
                        }
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (Exception exSub in ex.LoaderExceptions)
                        {
                            sb.AppendLine(exSub.Message);
                            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                            if (exFileNotFound != null)
                            {
                                if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                                {
                                    sb.AppendLine("Fusion Log:");
                                    sb.AppendLine(exFileNotFound.FusionLog);
                                }
                            }
                            sb.AppendLine();
                        }
                        string errorMessage = sb.ToString();
                        throw new Exception(errorMessage);
                    }
                }
            }

            ICollection plugins = new List(pluginTypes.Count);
            foreach (Type type in pluginTypes)
            {
                try
                {
                    IPlugin plugin = (IPlugin)Activator.CreateInstance(type);
                    plugins.Add(plugin);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Couldn't Load {0} Reason:{1}", type, ex.Message);
                }
            }
            assemblies.Clear();
            pluginTypes.Clear();

            return plugins;
        }
    

开发者ID: KillzXGaming,   项目名称: Switch-Toolbox,   代码行数: 90,   代码来源: PluginLoader.cs

在KillzXGaming提供的LoadPlugins()方法中,该源代码示例一共有90行, 其中使用了FileNotFoundException.ToString()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString的代码示例5 - GetCodec()

    using System.IO;

        /// 
        ///     Returns a fully initialized  instance which is able to decode the specified file. If the
        ///     specified file can not be decoded, this method throws an .
        /// 
        /// Filename of the specified file.
        /// Fully initialized  instance which is able to decode the specified file.
        /// The codec of the specified file is not supported.
        public IWaveSource GetCodec(string filename)
        {
            if(String.IsNullOrEmpty(filename))
                throw new ArgumentNullException("filename");

            if (!File.Exists(filename))
                throw new FileNotFoundException("File not found.", filename);

            string extension = Path.GetExtension(filename).Remove(0, 1); //get the extension without the "dot".

            IWaveSource source = null;
            if (File.Exists(filename))
            {
                Stream stream = File.OpenRead(filename);
                try
                {
                    foreach (var codecEntry in _codecs)
                    {
                        try
                        {
                            if (
                                codecEntry.Value.FileExtensions.Any(
                                    x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)))
                            {
                                source = codecEntry.Value.GetCodecAction(stream);
                                if (source != null)
                                    break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }
                }
                finally
                {
                    if (source == null)
                    {
                        stream.Dispose();
                    }
                    else
                    {
                        source = new DisposeFileStreamSource(source, stream);
                    }
                }
            }

            if (source != null)
                return source;

            return Default(filename);
        }
    

开发者ID: filoe,   项目名称: cscore,   代码行数: 62,   代码来源: CodecFactory.cs

在filoe提供的GetCodec()方法中,该源代码示例一共有62行, 其中使用了FileNotFoundException.ToString()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString的代码示例6 - Get_Xml_Data()

    
        private XmlDocument Get_Xml_Data()
        {
            //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: {0}:getXmlData", this.ToString()));
            if (this.xmlData_ == null)
            {
                string filename = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar + "AsmDudeData.xml";
                Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: AsmDudeTools:getXmlData: going to load file \"{0}\"", filename));
                try
                {
                    this.xmlData_ = new XmlDocument() { XmlResolver = null };
                    System.IO.StringReader sreader = new System.IO.StringReader(File.ReadAllText(filename));
                    using (XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null }))
                    {
                        this.xmlData_.Load(reader);
                    }
                }
                catch (FileNotFoundException)
                {
                    AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: could not find file \"" + filename + "\".");
                }
                catch (XmlException)
                {
                    AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: xml error while reading file \"" + filename + "\".");
                }
                catch (Exception e)
                {
                    AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: error while reading file \"" + filename + "\"." + e);
                }
            }
            return this.xmlData_;
        }
    

开发者ID: HJLebbink,   项目名称: asm-dude,   代码行数: 32,   代码来源: AsmDudeTools.cs

在HJLebbink提供的Get_Xml_Data()方法中,该源代码示例一共有32行, 其中使用了FileNotFoundException.ToString()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileNotFoundException.ToString()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileNotFoundException.ToString()可能更有帮助。

FileNotFoundException.ToString()方法的常见问题及解答

C#中FileNotFoundException.ToString()的常见错误类型及注意事项

FileNotFoundException.ToString的错误类型有很多, 这里就不一一阐述了,本文只列出一些常见的代码示例供参考,大家可以看一下代码中Catch语句中是否有常见的错误捕获及处理。

C#中FileNotFoundException.ToString()的构造函数有哪些

FileNotFoundException.ToString构造函数功能基本类似,只是参数不同; 目前主流的集成开发环境都已经带智能提醒了,如:Visual Studio; 大家可以非常轻松的通过Visual Studio中的智能提醒,了解对应构造函数的用法。

如何使用ChartGPT写一段FileNotFoundException.ToString的代码

你可以在ChartGPT中输入如下的指令:"提供一个如何使用FileNotFoundException.ToString的C#代码示例"
ChartGPT写出的代码和本文中的小编提供的代码的区别。 ChartGPT发展到现在已经非常聪明了,但需要使用这提供非常专业的问题,才可能有比较好的源代码示例; 而本文中, 小编已经帮您列出来基本所有类和所有方法的使用示例, 而且这些示例基本都是一些网络大佬提供的源码,可以更方便的供一些开发菜鸟或者资深开发参考和学习。

FileNotFoundException.ToString所在的类及名称空间

FileNotFoundException.ToString是System.IO下的方法。

FileNotFoundException.ToString怎么使用?

FileNotFoundException.ToString使用上比较简单,可以参考MSDN中的帮助文档,也参考本文中提供的7个使用示例。

FileNotFoundException.ToString菜鸟教程

对于菜鸟来说,本文中提供的7个FileNotFoundException.ToString写法都将非常直观的帮您掌握FileNotFoundException.ToString的用法,是一个不错的参考教程。

本文中的FileNotFoundException.ToString方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。