C# Path.GetTempPath的代码示例

通过代码示例来学习C# Path.GetTempPath方法

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


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

Path.GetTempPath的代码示例1 - New()

    using System.IO;

        public void New()
        {
            tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            int tries = 1;
            var baseFolder = tempFolder;
            while (Directory.Exists(tempFolder) && tries < 3)
            {
                tempFolder = $"{baseFolder}_{tries}";
                tries++;
            }
            if (tries >= 3)
                throw new Exception("Failed to create temporary folder");

            Directory.CreateDirectory(tempFolder);
        }
    

开发者ID:emoose,项目名称:DLSSTweaks,代码行数:17,代码来源:Utility.cs

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

Path.GetTempPath的代码示例2 - PrefetchFilesFromFileListFile()

    using System.IO;

        [TestCase, Order(12)]
        public void PrefetchFilesFromFileListFile()
        {
            string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file");
            try
            {
                File.WriteAllLines(
                    tempFilePath,
                    new[]
                    {
                        Path.Combine("GVFS", "GVFS", "Program.cs"),
                        Path.Combine("GVFS", "GVFS.FunctionalTests", "GVFS.FunctionalTests.csproj")
                    });

                this.ExpectBlobCount(this.Enlistment.Prefetch($"--files-list \"{tempFilePath}\""), 2);
            }
            finally
            {
                File.Delete(tempFilePath);
            }
        }
    

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

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

Path.GetTempPath的代码示例3 - Application_Startup()

    using System.IO;

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            splashscreen = new SplashScreen();
            splashscreen.Show();
            App.DoEvents();

            byte[] msiData = WpfSetup.Properties.Resources.MyProduct_msi;
            MsiFile = Path.Combine(Path.GetTempPath(), "MyProduct.msi");

            if (!File.Exists(MsiFile) || new FileInfo(MsiFile).Length != msiData.Length)
                File.WriteAllBytes(MsiFile, msiData);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:16,代码来源:App.xaml.cs

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

Path.GetTempPath的代码示例4 - viewLog_LinkClicked()

    using System.IO;

        void viewLog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                string logFile = Runtime.Session.LogFile;

                if (logFile.IsEmpty())
                {
                    string wixSharpDir = Path.GetTempPath().PathCombine("WixSharp");

                    if (!Directory.Exists(wixSharpDir))
                        Directory.CreateDirectory(wixSharpDir);

                    logFile = wixSharpDir.PathCombine(Runtime.ProductName + ".log");
                    System.IO.File.WriteAllText(logFile, Shell.Log);
                }
                Process.Start("notepad.exe", logFile);
            }
            catch
            {
                //Catch all, we don't want the installer to crash in an
                //attempt to view the log.
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:26,代码来源:ExitDialog.cs

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

Path.GetTempPath的代码示例5 - Shoud_Resolve_WixVars()

    using System.IO;

        [Fact]
        public void Shoud_Resolve_WixVars()
        {
            string asWixVarToPath(string name) => name.AsWixVarToPath();

            var adminToolsFolder = asWixVarToPath("AdminToolsFolder");
            var appDataFolder = asWixVarToPath("AppDataFolder");
            var commonAppDataFolder = asWixVarToPath("CommonAppDataFolder");
            var commonFiles64Folder = asWixVarToPath("CommonFiles64Folder");
            var commonFilesFolder = asWixVarToPath("CommonFilesFolder");
            var desktopFolder = asWixVarToPath("DesktopFolder");
            var favoritesFolder = asWixVarToPath("FavoritesFolder");
            var programFiles64Folder = asWixVarToPath("ProgramFiles64Folder");
            var programFilesFolder = asWixVarToPath("ProgramFilesFolder");
            var myPicturesFolder = asWixVarToPath("MyPicturesFolder");
            var sendToFolder = asWixVarToPath("SendToFolder");
            var localAppDataFolder = asWixVarToPath("LocalAppDataFolder");
            var personalFolder = asWixVarToPath("PersonalFolder");
            var startMenuFolder = asWixVarToPath("StartMenuFolder");
            var startupFolder = asWixVarToPath("StartupFolder");
            var programMenuFolder = asWixVarToPath("ProgramMenuFolder");
            var system16Folder = asWixVarToPath("System16Folder");
            var system64Folder = asWixVarToPath("System64Folder");
            var systemFolder = asWixVarToPath("SystemFolder");
            var templateFolder = asWixVarToPath("TemplateFolder");
            var windowsVolume = asWixVarToPath("WindowsVolume");
            var windowsFolder = asWixVarToPath("WindowsFolder");
            var fontsFolder = asWixVarToPath("FontsFolder");
            var tempFolder = asWixVarToPath("TempFolder");

            bool isValid(string dir, string ending) => io.Directory.Exists(dir) && dir.EndsWith(ending, StringComparison.OrdinalIgnoreCase);

            //expected to be tested on OS Vista or above from the x86 runtime
            Assert.True(isValid(adminToolsFolder, "Administrative Tools"));
            Assert.True(isValid(appDataFolder, @"AppData\Roaming"));
            Assert.True(isValid(commonAppDataFolder, "ProgramData"));
            Assert.True(isValid(commonFiles64Folder, "Common Files"));
            Assert.True(isValid(commonFilesFolder, "Common Files"));
            Assert.True(isValid(desktopFolder, "Desktop"));
            Assert.True(isValid(favoritesFolder, "Favorites"));
            Assert.True(isValid(programFiles64Folder, "Program Files"));
            if (Environment.Is64BitProcess)
                Assert.True(isValid(programFilesFolder, "Program Files"));
            else
                Assert.True(isValid(programFilesFolder, "Program Files (x86)"));
            Assert.True(isValid(myPicturesFolder, "Pictures"));
            Assert.True(isValid(sendToFolder, "SendTo"));
            Assert.True(isValid(localAppDataFolder, "Local"));
            Assert.True(isValid(personalFolder, "Documents"));
            Assert.True(isValid(startMenuFolder, "Start Menu"));
            Assert.True(isValid(startupFolder, "Startup"));
            Assert.True(isValid(programMenuFolder, "Programs"));
            Assert.True(isValid(system16Folder, "system"));
            Assert.True(isValid(system64Folder, "system32"));
            Assert.True(isValid(systemFolder, "SysWow64"));
            Assert.True(isValid(templateFolder, "Templates"));
            Assert.True(isValid(windowsVolume, @"C:\"));
            Assert.True(isValid(windowsFolder, @"C:\Windows"));
            Assert.True(isValid(fontsFolder, @"C:\Windows\Fonts"));
            Assert.True(isValid(tempFolder, System.IO.Path.GetTempPath()));
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:63,代码来源:GenericTest.cs

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

Path.GetTempPath的代码示例6 - print_Click()

    using System.IO;

        void print_Click(object sender, EventArgs e)
        {
            try
            {
                var file = Path.Combine(Path.GetTempPath(), Runtime.Session.Property("ProductName") + ".licence.rtf");
                io.File.WriteAllText(file, agreement.Rtf);
                Process.Start(file);
            }
            catch
            {
                //Catch all, we don't want the installer to crash in an
                //attempt to write to a file.
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:16,代码来源:LicenceDialog.cs

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

Path.GetTempPath的代码示例7 - AsWixVarToPath()

    using System.IO;

        /// 
        /// 'Interprets' a string as a WiX constant and expands into a proper File System path. For example "DesktopFolder"
        /// will be expanded into "[SysDrive]:\Users\[user]\Desktop". This method is a logical equivalent of C# Environment.GetFolderPath.
        /// Though it handles discrepancies between 'special folders' mapping in .NET and WiX.
        ///
        /// 
        /// The method will always be called from x86 runtime as MSI always loads ManagedUI in x86 host.
        /// From the other hand CustomActions are called in the deployment specific CPU type context.
        /// 
        /// 
        /// The path.
        /// 
        public static string AsWixVarToPath(this string path)
        {
            switch (path)
            {
                case "AdminToolsFolder":
                    return Environment.SpecialFolder.ApplicationData.ToPath().PathJoin(@"Microsoft\Windows\Start Menu\Programs\Administrative Tools");

                case "AppDataFolder": return Environment.SpecialFolder.ApplicationData.ToPath();
                case "CommonAppDataFolder": return Environment.SpecialFolder.CommonApplicationData.ToPath();

                case "CommonFiles64Folder": return Environment.SpecialFolder.CommonProgramFiles.ToPath().Replace(" (x86)", "");
                case "CommonFilesFolder": return Environment.SpecialFolder.CommonProgramFiles.ToPath();

                case "DesktopFolder": return Environment.SpecialFolder.Desktop.ToPath();
                case "FavoritesFolder": return Environment.SpecialFolder.Favorites.ToPath();

                case "ProgramFiles64Folder": return Environment.SpecialFolder.ProgramFiles.ToPath().Replace(" (x86)", "");
                case "ProgramFilesFolder": return Environment.SpecialFolder.ProgramFiles.ToPath();

                case "MyPicturesFolder": return Environment.SpecialFolder.MyPictures.ToPath();
                case "SendToFolder": return Environment.SpecialFolder.SendTo.ToPath();
                case "LocalAppDataFolder": return Environment.SpecialFolder.LocalApplicationData.ToPath();
                case "PersonalFolder": return Environment.SpecialFolder.Personal.ToPath();

                case "StartMenuFolder": return Environment.SpecialFolder.StartMenu.ToPath();
                case "StartupFolder": return Environment.SpecialFolder.Startup.ToPath();
                case "ProgramMenuFolder": return Environment.SpecialFolder.Programs.ToPath();

                case "System16Folder": return Path.Combine("WindowsFolder".AsWixVarToPath(), "System");
                case "System64Folder": return Environment.SpecialFolder.System.ToPath();
                case "SystemFolder": return Is64OS() ? Path.Combine("WindowsFolder".AsWixVarToPath(), "SysWow64") : Environment.SpecialFolder.System.ToPath();

                case "TemplateFolder": return Environment.SpecialFolder.Templates.ToPath();
                case "WindowsVolume": return Path.GetPathRoot(Environment.SpecialFolder.Programs.ToPath());
                case "WindowsFolder": return Environment.SpecialFolder.System.ToPath().PathGetDirName();
                case "FontsFolder": return Environment.SpecialFolder.System.ToPath().PathGetDirName().PathJoin("Fonts");
                case "TempFolder": return Path.GetTempPath();
                // case "TempFolder": return Path.GetDirectoryName(Environment.SpecialFolder.Desktop.ToPath().Ge, @"Local Settings\Temp");
                default:
                    return path;
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:56,代码来源:SharedExtensions.cs

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

Path.GetTempPath的代码示例8 - SetUpFileSystemWatcher()

    using System.IO;

        private void SetUpFileSystemWatcher()
        {
            FileWatcher = new FileSystemWatcher();
            FileWatcher.Path = Path.GetTempPath();
            FileWatcher.NotifyFilter = NotifyFilters.Attributes |
                NotifyFilters.CreationTime |
                NotifyFilters.FileName |
                NotifyFilters.LastAccess |
                NotifyFilters.LastWrite |
                NotifyFilters.Size |
                NotifyFilters.Security;

            FileWatcher.EnableRaisingEvents = false;
            FileWatcher.Changed += new FileSystemEventHandler(OnFileWatcherChanged);
            FileWatcher.Filter = "";
        }
    

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

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

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