System.IO.Path.GetRandomFileName C# (CSharp) Méthode

GetRandomFileName() public static méthode

public static GetRandomFileName ( ) : string
Résultat string
        public static unsafe string GetRandomFileName()
        {
            // 8 random bytes provides 12 chars in our encoding for the 8.3 name.
            const int KeyLength = 8;
            byte* pKey = stackalloc byte[KeyLength];
            GetCryptoRandomBytes(pKey, KeyLength);

            const int RandomFileNameLength = 12;
            char* pRandomFileName = stackalloc char[RandomFileNameLength];
            Populate83FileNameFromRandomBytes(pKey, KeyLength, pRandomFileName, RandomFileNameLength);
            return new string(pRandomFileName, 0, RandomFileNameLength);
        }

Usage Example

        void NotifyWebAppisHosted(string webAppVersionString)
        {
            WebAppVersion = webAppVersionString;
            string jsResults;

            using (var context = new AutoJSContext(_browser.Window.JSContext))
                using (new JSAutoCompartment(context, (nsISupports)_browser.Window.DomWindow))
                {
                    context.EvaluateScript("hostedAppSetup();", out jsResults);
                }

            //This loads the last saved program. We know at this point that everything should be working in Blockly.
            if (!string.IsNullOrWhiteSpace(Settings.Default.SavedProgram))
            {
                string tempPath = IOPath.Combine(IOPath.GetTempPath(), IOPath.GetRandomFileName());
                Directory.CreateDirectory(tempPath);
                string tempLoadingFile = IOPath.Combine(tempPath, "temp_blocks.xml");
                using (var file = File.OpenWrite(tempLoadingFile))
                    using (var sw = new StreamWriter(file))
                    {
                        sw.Write(Settings.Default.SavedProgram);
                    }
                _tempPathsCreated.Add(tempPath);
                string fileUri = "file://" + new FileInfo(tempLoadingFile).FullName;

                using (var context = new AutoJSContext(_browser.Window.JSContext))
                    using (var compartment = new JSAutoCompartment(context, (nsISupports)_browser.Window.DomWindow))
                    {
                        string output;
                        context.EvaluateScript("load_by_url('" + fileUri.Replace("\\", "/") + "');", out output);
                    }
            }
        }
All Usage Examples Of System.IO.Path::GetRandomFileName