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

WriteAllLines() public static méthode

public static WriteAllLines ( string path, System contents ) : void
path string
contents System
Résultat void
        public static void WriteAllLines(string path, System.Collections.Generic.IEnumerable<string> contents) { }
        public static void WriteAllLines(string path, string[] contents, System.Text.Encoding encoding) { }

Same methods

File::WriteAllLines ( String path, IEnumerable contents ) : void
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, 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