C# 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

在TryDeleteStatusCacheFile()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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

在TryCopyNativeLibIfDriverVersionsMatch()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞

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

在Upload()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

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

在LoadPlugins()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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

在GetCodec()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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

在Get_Xml_Data()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileNotFoundException.ToString的代码示例7 - GetProviderFactory()

    using System.IO;

        /// 获取提供者工厂
        /// 
        /// 
        /// 
        /// 
        /// 
        public static DbProviderFactory GetProviderFactory(String assemblyFile, String className, Boolean strict = false, Boolean ignoreError = false)
        {
            try
            {
                var links = GetLinkNames(assemblyFile, strict);
                var type = PluginHelper.LoadPlugin(className, null, assemblyFile, links.Join(","));

                // 反射实现获取数据库工厂
                var file = assemblyFile;
                var plugin = NewLife.Setting.Current.GetPluginPath();
                file = plugin.CombinePath(file);

                // 如果还没有,就写异常
                if (type == null)
                {
                    if (assemblyFile.IsNullOrEmpty()) return null;
                    if (!File.Exists(file)) throw new FileNotFoundException("缺少文件" + file + "!", file);
                }

                if (type == null)
                {
                    XTrace.WriteLine("驱动文件[{0}]无效或不适用于当前环境,准备删除后重新加载[{1}]!", assemblyFile, file);

                    try
                    {
                        File.Delete(file);
                    }
                    catch (UnauthorizedAccessException) { }
                    catch (Exception ex) { XTrace.Log.Error(ex.ToString()); }

                    type = PluginHelper.LoadPlugin(className, null, file, links.Join(","));

                    // 如果还没有,就写异常
                    if (!File.Exists(file)) throw new FileNotFoundException("缺少文件" + file + "!", file);
                }
                //if (type == null) return null;
                if (type == null) throw new XCodeException("无法加载驱动[{0}],请从nuget正确引入数据库驱动!", assemblyFile);

                var asm = type.Assembly;
                if (DAL.Debug) DAL.WriteLog("{2}驱动{0} 版本v{1}", asm.Location, asm.GetName().Version, className.TrimEnd("Client", "Factory"));

                var field = type.GetFieldEx("Instance");
                if (field == null) return Activator.CreateInstance(type) as DbProviderFactory;

                return Reflect.GetValue(null, field) as DbProviderFactory;
            }
            catch
            {
                if (ignoreError) return null;

                throw;
            }
        }
    

开发者ID:NewLifeX,项目名称:X,代码行数:61,代码来源:DbBase.cs

在GetProviderFactory()方法中,FileNotFoundException的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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