System.IO.File.WriteAllLines C# (CSharp) Méthode

WriteAllLines() public static méthode

public static WriteAllLines ( String path, IEnumerable contents ) : void
path String
contents IEnumerable
Résultat void
        public static void WriteAllLines(String path, IEnumerable<String> contents)
        {
            if (path == null)
                throw new ArgumentNullException(nameof(path));
            if (contents == null)
                throw new ArgumentNullException(nameof(contents));
            if (path.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyPath, nameof(path));
            Contract.EndContractBlock();

            InternalWriteAllLines(new StreamWriter(path), contents);
        }

Same methods

File::WriteAllLines ( String path, IEnumerable contents, Encoding encoding ) : void
File::WriteAllLines ( String path, String contents ) : void
File::WriteAllLines ( String path, String contents, Encoding encoding ) : void
File::WriteAllLines ( string path, System contents ) : void
File::WriteAllLines ( string path, System contents, System encoding ) : void
File::WriteAllLines ( string path, string contents ) : void
File::WriteAllLines ( string path, string contents, System encoding ) : void

Usage Example

Exemple #1
0
        private void AddTermsAndConditionsPage()
        {
            var migrationName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
                if (File.Exists(path))
                {
                    return;
                }

                var contentService = ApplicationContext.Current.Services.ContentService;
                var rootContent    = contentService.GetRootContent().FirstOrDefault();
                if (rootContent != null)
                {
                    var termsAndConditionsContent = rootContent.Children().FirstOrDefault(x => x.Name == "Terms and conditions");
                    if (termsAndConditionsContent == null)
                    {
                        var content = contentService.CreateContent("Terms and conditions", rootContent.Id, "TextPage");
                        content.SetValue("bodyText", "<p>These are our terms and conditions...:</p>");
                        var status = contentService.SaveAndPublishWithStatus(content);
                    }
                }

                string[] lines = { "" };
                File.WriteAllLines(path, lines);
            }
            catch (Exception ex)
            {
                LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
            }
        }
All Usage Examples Of System.IO.File::WriteAllLines